Python 3.x 一个组合框、一个按钮和;Tkinter中的两页

Python 3.x 一个组合框、一个按钮和;Tkinter中的两页,python-3.x,tkinter,Python 3.x,Tkinter,这是一篇关于同一问题的修订文章。使用tkinter,我想在一个框架(FrameFour)中添加一个按钮,当在组合框中选择某个值时,它会打开一个页面。例如,如果选择1并单击按钮,则frameOne应打开;如果选择2并单击按钮,则FrameII应打开。我为FrameFour编写的代码如下 class PageFour(tk.Frame): def __init__(self, parent,controller): tk.Frame.__init__(self,parent) s

这是一篇关于同一问题的修订文章。使用tkinter,我想在一个框架(FrameFour)中添加一个按钮,当在组合框中选择某个值时,它会打开一个页面。例如,如果选择1并单击按钮,则frameOne应打开;如果选择2并单击按钮,则FrameII应打开。我为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()缺少1个必需的位置参数:'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)

请考虑添加一个代码示例,或者修改您在这个问题中发布的代码。目前,它的格式和范围使我们很难帮助您;这是一个让你开始学习的方法。祝你的代码好运!你好,ReblochonMasque。谢谢你的回复,帖子已经修改了。干杯。非常感谢您的回复@Novel。然而,它仍然不起作用。无论如何,我现在已经用更新修改了帖子。Cheers@ConstantLearner我编辑了我的答案以向您展示如何解决错误。FWIW这是一个非常基本的错误,你应该能够在没有帮助的情况下解决。我建议您回到基础上来,浏览一些python初学者教程。也许可以尝试像learnpython.reddit.com这样的初学者论坛寻求帮助。效果非常好。非常感谢。我仍然是一个新手,在学习过程中我一定比自己跳得快:-)。一定会去初学者论坛看看。