2017-09-19 8 views
0
class Login: 
    def __init__(self): 
     Label1 = Label(root,text = "Username") 
     Label2 = Label(root,text = "Password") 
     self.Entry1 = Entry(root) 
     self.Entry2 = Entry(root,show = "*") 

     Label1.grid(row=0) 
     Label2.grid(row=1) 

     self.Entry1.grid(row = 0,column = 1) 
     self.Entry2.grid(row = 1,column = 1) 

     root.minsize(width = 300,height = 80) 
     ##new_window_button = Button(text="new window", command = ????) 
     ##new_window_button.grid(columnspan = 2) 

     lgbutton = Button(text = "Login",command = self.ButtonClicked) 
     lgbutton.grid(columnspan = 2) 


    def ButtonClicked(self): 
      username = self.Entry1.get() 
      password = self.Entry2.get() 
      GetDatabase(username,password) 

現在のところ、これは私がウィンドウを作成する必要がありますが、new_window_buttonがクリックされると、新しいページには独自のウィジェットがあります。以前はToplevelを使っていましたが、ウィジェットのない子ウィンドウが作成されます。代わりに、ウィジェットは親ウィンドウに追加されます。python tkinterで現在のウィンドウから新しいフレームを開くには?

+0

、新しいトップレベルを作成する方法を知っている、とあなただけ:

Label(top, text="I'm in the top window.") # ^This is the parent 

下記より肉付け例を参照してください苦情はタイトルですか?ウィンドウのタイトルを変更する方法を調べるための調査は行っていますか? –

+1

Toplevelウィンドウのルートウィンドウのタイトルを変更する同じ方法を試しましたか? –

+0

いいえ、タイトルの名前は問題ではありませんが、明らかに私はそれを今解決しました。しかし、新しいウィンドウを作成して新しいウィジェットを作成すると、そのウィジェットが親に追加されます。 –

答えて

1

コメントで判断すると、ウィジェットの正しい親を宣言することに苦労しているように見えます。

ウィジェットが宣言されたときに、渡された最初のパラメータはその親です。例えば:とは対照的に、

Label(root, text="I'm in the root window.") 
# ^This is the parent 

:だから

from tkinter import * 

root = Tk() 

top = Toplevel(root) 

label1 = Label(root, text="I'm a placeholder in your root window.") 
label2 = Label(top, text="I'm a placeholder in your top window.") 

label1.pack() 
label2.pack() 

root.mainloop() 
関連する問題