无法检查列表框中的项目是否已被点击。

huangapple go评论71阅读模式
英文:

Cannot check if item in listbox was clicked

问题

from tkinter import *

top = Toplevel()
top.geometry('255x135')
top.resizable(False, False)
guessbox = Listbox(master=top, selectmode=SINGLE)
guessbox.insert(0, '0')
guessbox.insert(1, '1')

guessbox.place(x=0, y=0)
answer = random.randint(0, 1)
dirlabel = Label(master=top, text='Click Next when done')
dirlabel.place(x=130, y=0)
nextbutton = Button(master=top, text='Next', command=top.quit, state='disabled')
nextbutton.place(x=170, y=50)
guess = guessbox.curselection()
print(guess)
guessbox.bind('<<ListboxSelect>>', nextbutton.config(state='normal'))
英文:

I am trying to check and see if an item in a listbox was selected and then enable another button if there is an item selected from the listbox.

from tkinter import *

top = Toplevel()
top.geometry(&#39;255x135&#39;)
top.resizable(False, False)
guessbox = Listbox(master=top, selectmode=SINGLE)
guessbox.insert(0, &#39;0&#39;)
guessbox.insert(1, &#39;1&#39;)

guessbox.place(x=0, y=0)
answer = random.randint(0, 1)
dirlabel = Label(master=top, text=&#39;Click Next when done&#39;)
dirlabel.place(x=130, y=0)
nextbutton = Button(master=top, text=&#39;Next&#39;, command=top.quit, state=&#39;disabled&#39;)
nextbutton.place(x=170, y=50)
guess = guessbox.curselection()
print(guess)
guessbox.bind(&#39;&lt;&lt;ListboxSelect&gt;&gt;&#39;, nextbutton.config(state=&#39;normal&#39;))

答案1

得分: 0

Add function for this.

Code:

def selected_item():
    for i in guessbox.curselection():
        print(guessbox.get(i))

nextbutton = Button(...command=selected_item,...
英文:

Add function for this.

Code:

def selected_item():
    for i in guessbox.curselection():
        print(guessbox.get(i))

nextbutton = Button(...command=selected_item,...

huangapple
  • 本文由 发表于 2023年4月1日 00:11:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/75900656.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定