簡體   English   中英

Tkinter標簽位於框架的底部

[英]Tkinter label go at the bottom of the frame

我使用Tkinter和包布局管理的小Python應用程序有點問題。 我不明白為什么標簽會放在框架的底部。

這是代碼:

class App:

def __init__(self, master):

    frame = Frame(master)
    frame.pack()

    photo = PhotoImage(file="icone.gif")
    self.label = Label(image=photo)
    self.label.image = photo # keep a reference!
    self.label.pack()

    self.labelNet = Label(master, text='NetID:')
    self.labelNet.pack()

    self.netID = Entry(frame,width=20)
    self.netID.pack()

    self.password = Label(master, text='Password:')
    self.password.pack()

    self.password = Entry(frame, show="*",  width=20)
    self.password.pack()

    self.install = Button(frame, text="Activer", command=self.install)
    self.install.pack()

    self.uninstall = Button(frame, text="Désactiver", command=self.uninstall)
    self.uninstall.pack()

致電者:

root = Tk()
root.title("Title")
root.geometry("200x280")
app = App(root)
root.mainloop()

結果:

您知道可能是什么問題嗎?

謝謝 !

self.label = Label(image=photo)
...
self.labelNet = Label(master, text='NetID:')
...
self.password = Label(master, text='Password:')

您所有的標簽都使用master作為其master,或者您未提供master(在這種情況下,默認為根窗口)。 您所有其他小部件都將框架作為其主框架。 這有效地導致您具有以下窗口小部件層次結構:

root
    frame
        entry
        entry
        button
        button
    label
    label
    label

您還應該使標簽也以框架為原版。

self.label = Label(frame, image=photo)
...
self.labelNet = Label(frame, text='NetID:')
...
self.password = Label(frame, text='Password:')

或者,或者,根本就沒有框架,而使所有東西都成為根的直接子代。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM