Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python tkinter实例未显示_Python_Tkinter - Fatal编程技术网

Python tkinter实例未显示

Python tkinter实例未显示,python,tkinter,Python,Tkinter,我想做GUI,我想把GUI分成几个类。(注意:一般来说,我对编程非常陌生)。在main类中,我将调用实例(GUI的一部分)并使用网格创建完整的GUI。问题是,在我看来,在我的主类中,应该决定将实例放在哪里,但只显示最后一个实例 import tkinter as tk import tkinter.ttk as ttk class Code(tk.Frame): def __init__(self, parent, *args): tk.Frame.__init__(s

我想做GUI,我想把GUI分成几个类。(注意:一般来说,我对编程非常陌生)。在main类中,我将调用实例(GUI的一部分)并使用网格创建完整的GUI。问题是,在我看来,在我的主类中,应该决定将实例放在哪里,但只显示最后一个实例

import tkinter as tk
import tkinter.ttk as ttk

class Code(tk.Frame):
    def __init__(self, parent, *args):
        tk.Frame.__init__(self, parent)

        self.frm = ttk.LabelFrame(parent, text="frm_code", height=130, width=500)
        # make grid with just one cell - I thought this is local grid placement
        self.frm.grid(row=0, column=0, sticky=(tk.N, tk.S, tk.W, tk.E))
        self.frm.grid_propagate(False)

        self.mess_sql = tk.Message(
            self.frm,
            text="""Veeeery long text""",
            width = 470
        )
        self.mess_sql.grid(row=0, column=0, sticky=(tk.N, tk.S, tk.W, tk.E))

class Header(tk.Frame):
    def __init__(self, parent):
        tk.Frame.__init__(self, parent)

        self.frm = ttk.LabelFrame(parent, text="frm_header")
        # make grid with just one cell - I thought this is local grid placement
        self.frm.grid(row=0, column=0, sticky=(tk.N, tk.S, tk.W, tk.E))

        self.btn_ok = ttk.Button(self.frm, text="OK", command=self.click_ok)
        self.btn_cancel= ttk.Button(self.frm, text="Cancel", command=self.click_cancel)

        self.btn_ok.grid(row=0, column=0)
        self.btn_cancel.grid(row=0, column=1)

    # just some test functions
    def click_ok(self):
        print("OK clicked")
    def click_cancel(self):
        print("Cancel clicked")

class App(tk.Frame):
    def __init__(self, parent):
        tk.Frame.__init__(self, parent)

        self.header = Header(parent)
        self.code = Code(parent)

        # this should place widgets, but for now does nothing
        self.header.grid(row=0, column=0)
        self.header.grid(row=1, column=0)

if __name__ == '__main__':
    root = tk.Tk()
    app = App(root)
    root.mainloop()

您放置了两次标题框。行应该是
self.code.grid(row=1,column=0)
Yes,这是错误的,但即使我对这些行进行注释,也会得到相同的行为。让我困惑的是注释下方的那些行
#仅用一个单元格制作网格-我认为这是本地网格布局
,因为它们似乎决定了主类中的布局而不是网格。我已经看到了这个答案[link],并将我的代码修改为