Python - Tkinter条目显示在错误的窗口上

时间:2016-11-23 12:07:34

标签: python tkinter window tkinter-entry

当条目窗口小部件加载到测试窗口内部时,新窗口会加载,但窗口小部件会加载到第一个窗口中。知道我可以在这里改变什么。

import tkinter as tk

class programLauncher(tk.Frame):
    def __init__(self, *args, **kwargs):
        tk.Frame.__init__(self, *args, **kwargs)
        self.TESTING_btn = tk.Button(self, text = "TESTING", command = self.varTesting)
        self.TESTING_btn.pack(side = "right", expand=True)

    def varTesting(self):
        t = tk.Toplevel(self)
        t.wm_title("TESTING - Variables")
        warning = tk.Label(t, text = "WARNING TESTING ONLY")
        warning.grid(row = 0, column = 0)
        sysCap = tk.Label(t, text = "System Cap")
        sysCap.grid(row = 1, column = 0)
        sysCapInp = tk.Entry(bd = 5)
        sysCapInp.pack()


if __name__ == "__main__":
    root = tk.Tk()
    main = programLauncher(root)
    main.pack(side="top", fill="both", expand=True)
    root.mainloop()

2 个答案:

答案 0 :(得分:0)

您尚未向Entry小部件提供父级,因此会将其添加到根窗口。

答案 1 :(得分:0)

    sysCapInp = tk.Entry(Parent, bd = 5)
    sysCapInp.pack()

我还将其命名为self.sysCapInp,因此如果需要,您可以从其他地方调用sysCapInp .get()而不是在您的单个函数内部