python-3.x - 如何使单选按钮连接到文本文件中的一行并使其显示在框架上
问题描述
我创建了一个程序,它应该允许用户选择他们想要投票的候选人。我已经在一个单独的 python 文件上创建了这个类,但是在同一个文件夹中,并且使用了 import filename * 语句。当我单击按钮为候选人投票时,单选按钮和文本不会出现在框架上。
class LoginSuccessful(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="Greenwich Student Union Voting System", bg="blue", fg="white",
width="200", height="2", font=controller.title_font)
label.pack(side="top", fill="x", pady=10)
button = tk.Button(self, text="View Candidates", height="2", width="30",
command=lambda: controller.show_frame("ViewCandidates"))
button.pack()
label = tk.Label(self, text="", )
label.pack(side="top", fill="x", pady=10)
button1 = tk.Button(self, text="Vote for Candidates", height="2", width="30",
command=lambda: controller.show_frame("VoteForPresident"))
上面的代码在单独的 python 文件中,但是我使用 import 语句将 python 文件链接在一起
class VoteForPresident(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="Vote for your President ", bg="red", fg="white",
width="200", height="2", font=controller.title_font)
label.pack(side="top", fill="x", pady=10)
def selection(self):
radio = IntVar()
selection = msg.showinfo("Submit", "You have chosen President Barn as your preference " + str(radio.get()))
with open("PresidentCandidates.txt", "r") as f:
label = tk.Label(self, text=f.read())
label.pack(side="top", fill="x", pady=10)
r1 = Radiobutton(text="1ST PREFERENCE", variable=radio, value=1, command=selection)
r1.pack(side="top", fill="x", pady=10)
r2 = Radiobutton(text="2ND PREFERENCE", variable=radio, value=2, command=selection)
r2.pack(side="top", fill="x", pady=10)
r3 = Radiobutton(text="3RD PREFERENCE", variable=radio, value=3, command=selection)
r3.pack(side="top", fill="x", pady=10)
r4 = Radiobutton(text="4TH PREFERENCE", variable=radio, value=4, command=selection)
r4.pack(side="top", fill="x", pady=10)
label = tk.Label(self, text="")
label.pack(side="top", fill="x", pady=10)
button = tk.Button(self, text="Back", height="2", width="30",
command=lambda:
self.controller.show_frame("LoginSuccessful"))
button.pack()
解决方案
推荐阅读
- windows - 如何在windows中启动ksql?
- sqlite - 无法使用 Spring data jpa 正确连接到 SQlitedb
- c - 错误:数组类型“va_list”(又名“__builtin_va_list”)不可分配
- javascript - QueryString 未从底部设置的 javascript 执行
- sql - 比较两个日期以找出德比的时差
- symfony - 在内核响应侦听器中检索安全令牌
- reactjs - 如何在反应日期中显示单个日历?
- php - 连接数组以插入 mysql 表
- java - 我如何检查一个值,多个值是否满足以及它们是否记录?
- jquery - Jinja2 无法使用 JQuery 加载 html 文件