简体   繁体   English

Tkinter 一次显示所有页面,而不是一页一页地显示

[英]Tkinter shows all pages at once rather than one by one

I have been trying to make a data entry application, that has pages to enter new categories, horses, etc. I have different pages for each but the problem is they are all called at once rather than one by one upon request.我一直在尝试制作一个数据输入应用程序,该应用程序具有用于输入新类别、马匹等的页面。每个页面都有不同的页面,但问题是它们都是一次性调用的,而不是根据请求一个一个调用。 When I run it I get a window with all the things I have packed and the buttons are not responding to anything.当我运行它时,我会看到一个窗口,里面有我打包的所有东西,但按钮没有任何响应。

Here is my code:这是我的代码:

class App(tk.Tk):

    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        container = tk.Frame(self)

        container.pack(side="top", fill="both", expand=True)

        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames = {}

        for F in (MainMenu, AddData, AddHorse, AddCategory):
            frame = F(container, self)
            self.frames[F] = frame
            frame.pack()

        self.show_frame(MainMenu)

    def show_frame(self, cont):
        frame = self.frames[cont]
        frame.tkraise()


class MainMenu(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)

        add_category_btn = tk.Button(self, text="Add Category",
                                 command=lambda: controller.show_frame(AddCategory))
        add_horse_btn = tk.Button(self, text="Add Horse",
                             command=lambda: controller.show_frame(AddHorse))
        add_data_btn = tk.Button(self, text="Add Data",
                             command=lambda: controller.show_frame(AddData))

        add_category_btn.pack()
        add_horse_btn.pack()
        add_data_btn.pack()

class AddCategory(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        label = tk.Label(self, text='Add Category')
        label.pack()
        home_button = tk.Button(self, text='Go Home',
                            command=lambda: controller.show_frame(MainMenu))
        home_button.pack()


class AddHorse(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        label = tk.Label(self, text='Add Horse')
        label.pack()
        home_button = tk.Button(self, text='Go Home',
                            command=lambda: controller.show_frame(MainMenu))
        home_button.pack()


class AddData(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        label = tk.Label(self, text='Add Data')
        label.pack()
        home_button = tk.Button(self, text='Go Home',
                            command=lambda: controller.show_frame(MainMenu))
        home_button.pack()

app = App()
app.mainloop()

The code you copied uses grid , not pack for the frames.您复制的代码使用grid ,而不是为框架pack This code only works with grid for the pages.此代码仅适用于页面的grid

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用writer.writerows(reader)在python3中一一而不是一次写入csv行 - write csv rows one by one rather than all at once in python3 using writer.writerows(reader) Tkinter:一次移动多个对象 - Tkinter : Moving more than one object at once 在我的 Tkinter gui 中,我能否让我的选项菜单只显示在一个选项卡上而不是所有三个选项卡上? - Can I have my options menu display only on one tab rather than all three in my Tkinter gui? 逻辑测试所有值,而不是一个python - Logic tests all values rather than one python 我正在对 influenster.com 执行 web 刮擦。 我应该如何从所有 11 页而不是单页中获取评论 - I am performing web scraping on influenster.com. How am I supposed to get the reviews from all 11 pages rather than one single page 使用函数而不是一个衬里 Python - Using Functions rather than one liners Python 为什么我的查询仅在我的sqlalchemy flask应用程序中显示一个变量,而不是所有变量? - Why is my query only showing one variable in my sqlalchemy flask app rather than all? 如何让python在列表中搜索一个单词而不是列表中所有单词的文本? - How do I get python to search text for one word in a list rather than all the words in a list? 如何将DataFrame中列的所有值相乘而不是仅根据位置相乘? - How to multiply all values of column in DataFrame rather than just one based on location? Plotly:有没有办法只更改其中一个 add_trace 元素而不是全部? - Plotly: Is there a way to only change one of the add_trace elements rather than all?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM