英文:
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('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'))
答案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,...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论