python-3.x - Tkinter 中的一个组合框、一个按钮和两个页面
问题描述
这是关于同一问题的修订帖子。使用 tkinter,我想向框架(FrameFour)添加一个按钮,当在组合框中选择某个值时打开一个页面。例如,如果选择 1 并单击按钮,则应该打开 frameOne,如果选择 2 并单击按钮,则应该打开 frameTwo。我对 FrameFour 的代码如下
class PageFour(tk.Frame):
def __init__(self, parent,controller):
tk.Frame.__init__(self,parent)
self.InitUI()
def nextButton(self,controller):
if self.mychoice.get()=='1':
controller.show_frame(PageTwo)
def InitUI(self):
self.mychoice=StringVar()
self.combo = ttk.Combobox(self,width =15, textvariable=self.mychoice)
self.combo['values']=(" ","1","2")
self.combo.grid(column=1, row=0)
self.label=ttk.Label(self, text="How many files do you want to Process?")
self.label.grid(column=0, row=0)
self.button=ttk.Button(self, text="Next",command=self.nextButton)
self.button.grid(column=1, row=1)
app = GUI_ATT() app.mainloop()
但现在我在运行代码时收到错误消息“TypeError: nextButton() missing 1 required positional argument: 'controller'”。所有其他页面都运行良好并正确链接到彼此。如果您需要更多信息,请告诉我。
干杯
解决方案
你已经有了按钮和命令,你不需要再做一次。尝试这个:
class PageFour(tk.Frame):
def __init__(self, parent,controller):
tk.Frame.__init__(self,parent)
self.controller = controller
self.InitUI()
def nextButton(self):
if self.mychoice.get()=='1':
self.controller.show_frame(PageTwo)
def InitUI(self):
self.mychoice=StringVar()
self.combo = ttk.Combobox(self,width =15, textvariable=self.mychoice)
self.combo['values']=(" ","1","2")
self.combo.grid(column=1, row=0)
self.label=ttk.Label(self, text="How many files do you want to Process?")
self.label.grid(column=0, row=0)
self.button=ttk.Button(self, text="Next",command=self.nextButton)
self.button.grid(column=1, row=1)
推荐阅读
- javascript - 使用 javascript 代理拦截方法调用时非法调用
- sql-server - 如何使用 SQL 服务器汇总汇总|SQL CUBE
- r - Plotting two subgroups of several groups against one another, when in long format
- python - Python - OTRS REST/SOAP API - python-otrs
- discord.py - 将 Adf.ly 与 Discord.py 一起使用
- java - 在组合关系中查找特定的调用者
- javascript - GETJson 将两个参数传递给服务器
- android - 以编程方式将视图添加到 ConstraintLayout
- python - 我该如何从 Twilio 中的特定房间获取数据?
- django - Nginx: 403 禁止 nginx/1.12.1 (Ubuntu)