2017-04-15 2 views
0

私は理由とその問題の解決方法を知りたいですか?ありがとうございました。私が入力したtkinterエントリウィジェットは、そのたびにすべてが埋められます。

import Tkinter 

def next_screen(): 
    input.place_forget() 
    search.place_forget() 
    account() 

def account(): 
    items = ["Username", "Password"] 
    details = Tkinter.LabelFrame(main, text = "Account Details") 
    details.pack(fill = "both", expand = "yes") 
    for item in items: 
     frame = Tkinter.Frame(details) 
     frame.pack(side = "top") 
     entry = Tkinter.Entry(frame, show = "*", textvariable = "StringVar") 
     entry.pack(side = "right") 
     label = Tkinter.Label(frame, text = item, padx = 15, pady = 15, width = 10) 
     label.pack(side = "left") 


main = Tkinter.Tk() 
main.title("Test") 
main.geometry("400x300") 
input = Tkinter.Button(main, text = "Input", command = next_screen) 
search = Tkinter.Button(main, text = "Search") 
input.place(height = 70, width = 90, x = "55", y = "105") 
search.place(height = 70, width = 90, x = "255", y = "105") 
main.mainloop() 

私はtkinterについて学び、何かを作ろうとしています。これらのコードを使用して、最初のフレームに2つのボタンを作成しようとしましたが、入力を押すと現在の2つのボタンが忘れられ、2つのエントリウィジェットとそのラベルがある新しいレイヤーが表示されます。それを実行して入力ウィジェットを入力しようとすると、すべての入力ウィジェットが埋められます。

答えて

0

それはあなたがまだ始まったばかりされている場合、それらすべてがtextvariable

に同じ値を共有し、このため、textvariableを使用していないん。これは、いくつかの高度な機能にのみ必要です。

また、初めには、placeを使用することを強くお勧めします。 gridおよび/またはpackを学んでみると、はるかに柔軟性があり、解像度やフォントの異なるさまざまなシステムでうまく反応するUIを簡単に作成できます。

関連する問題