【发布时间】:2016-05-01 11:17:28
【问题描述】:
所以我正在使用 tkinter 制作电影推荐 GUI。当用户选择一个单选按钮时,我希望它在新窗口中打开,其中包含选择。因此,如果有人选择喜剧,我可以在不同的电影中编码,并让它们在新窗口中随机弹出。我有打开窗口的命令,但我无法回调选定的选项。
from tkinter import *
class movie1:
def __init__(self, master):
self.master = master
master.title("Movie Recommendation")
self.label = Label(master, text= "Welcome to the movie recommendation application! \n Please select the genre of the movie you would like to see.")
self.label.pack(padx=25, pady=25)
CheckVar1 = StringVar()
self.radiobutton = Radiobutton(master, text = "Action", variable=CheckVar1, value=1, command=self.reco)
self.radiobutton.pack(side=TOP, padx=10, pady=10)
self.radiobutton = Radiobutton(master, text = "Comedy", variable=CheckVar1, value=2, command=self.reco)
self.radiobutton.pack(side=TOP, padx=10, pady=10)
self.radiobutton = Radiobutton(master, text = "Documentary", variable=CheckVar1, value=3, command=self.reco)
self.radiobutton.pack(side=TOP, padx=10, pady=10)
self.radiobutton = Radiobutton(master, text = "Horror", variable=CheckVar1, value=4, command=self.reco)
self.radiobutton.pack(side=TOP, padx=10, pady=10)
self.radiobutton = Radiobutton(master, text = "Romance", variable=CheckVar1, value=5, command=self.reco)
self.radiobutton.pack(side=TOP, padx=10, pady=10)
self.radiobutton.cget("value")
def reco(self):
self.newWindow = Toplevel(self.master)
if ("value") == 1:
print("1")
root = Tk()
my_gui = movie1(root)
root.mainloop()
【问题讨论】:
-
获取选中哪个 Radiobutton 的示例tutorialspoint.com/python/tk_radiobutton.htm
标签: python user-interface tkinter