【发布时间】:2018-06-14 13:40:36
【问题描述】:
大家好,需要一些有关 Python GUI (Tkinter) 的帮助。我遇到的问题是我试图让每个单选按钮产生不同的消息框,我试图解决它的方式不起作用并且想知道为什么它不起作用。 (下面是我正在使用的代码)
from tkinter.messagebox import *
from tkinter import *
def button_press():
if button1:
showinfo(title="Message", message="You selected to enter a new item.")
elif button2:
showinfo(title="Message", message="You selected to remove an item by its element number.")
root_window = Tk()
option_value = IntVar()
button1 = Radiobutton(root_window, text="Enter a new item.", variable=option_value, value=1, command=button_press)
button1.pack(anchor=W)
button2 = Radiobutton(root_window, text="Remove an item by its element number.", variable=option_value, value=2,command=button_press)
button2.pack(anchor=W)
root_window.mainloop()
【问题讨论】: