2016-10-05 13 views
0
checkLabel = ttk.Label(win,text = " Check Amount ", foreground = "blue") 
checkLabel.grid(row = 0 , column = 1) 
checkEntry = ttk.Entry(win, textvariable = checkVariable) 
checkEntry.grid(row = 1, column = 1, sticky = 'w') 

defualt入力フィールドを0に変更するにはどうすればよいですか?Pythonのデフォルトのtkinterエントリ値を変更する

答えて

0

Entryオブジェクトを作成する前に、checkVariableの値を''(空の文字列)に設定しますか?使用する文は

checkVariable.set('') 

だろう。しかし、その後checkVariableStringVarでなければならないであろう、そしてあなたは、整数値を望んでいた場合は整数に自分で入力値を変換する必要があります。

+0

これは空白に変更されますが、デフォルトの倍精度に設定して、プログラムが変更されていない場合はどうすればよいですか? – MDub

+0

文字列入力を使用します。入力が空白(つまり変更されていない)の場合、デフォルト値を返します。さもなければ変換されたテキスト入力を返しますか? – holdenweb

1

エントリウィジェットの関数.insert().delete()を使用します。ここに例があります。

entry = tk.Entry(root) 
entry.insert(END, "Hello") # this will start the entry with "Hello" in it 
# you may want to add a delay or something here. 
entry.delete(0, END) # this will delete everything inside the entry 
entry.insert(END, "WORLD") # and this will insert the word "WORLD" in the entry. 

もう1つの方法はTkinter StrVarです。 str変数の使用例を次に示します。

entry_var = tk.StrVar() 
entry_var.set("Hello") 
entry = tk.Entry(root, textvariable=entry_var) # when packing the widget 
# it should have the world "Hello" inside. 
# here is your delay or you can make a function call. 
entry_var.set("World") # this sets the entry widget text to "World" 
+0

私は入力フィールドにEntry.insert(END、 "1")を使用すると0.01を得る どうすればちょうど0.1を得ることができますか? – MDub

関連する問題