当您运行此代码并尝试检查检查按钮并单击按钮以打印出检查按钮的值时,它不起作用。我无法弄清楚为什么。无论是选中还是未选中,它都会打印出来。
from tkinter import *
def awesome():
def click_me():
print(var.get())
return
root = Tk()
root.title("a good try")
var = IntVar()
x = Checkbutton(root, text = "check me", variable = var)
y = Button(root, text = "click me", command = click_me)
x.pack()
y.pack()
root.mainloop()
return
def main():
main = Tk()
cool = Button(main, text = "click", command = awesome)
cool.pack()
main.mainloop()
main()
答案 0 :(得分:1)
将root = Tk()
更改为root = Toplevel()
需要将Toplevel()
用于在另一个窗口上打开的窗口。