Python知识分享网 - 专业的Python学习网站 学Python,上Python222
tkinter_nmt PDF 下载
匿名网友发布于:2024-08-14 11:52:45
(侵权举报)
(假如点击没反应,多刷新两次就OK!)

tkinter_nmt PDF 下载 图1

 

 

资料内容:

 

Here are some comments on how control variables are used with specific widgets:
Button: You can set its textvariable to a StringVar. Anytime that variable is
changed, the text on the button will be updated to display the new value. This is not
necessary unless the button’s text is actually going to change: use the text attribute
if the button’s label is static.
Checkbutton: Normally, you will set the widget’s variable option to an IntVar,
and that variable will be set to 1 when the checkbutton is turned on and to 0 when
it is turned off. However, you can pick different values for those two states with the
onvalue and offvalue options, respectively. You can even use a StringVar as the
checkbutton’s variable, and supply string values for the offvalue and onvalue.
Here’s an example:
self.spamVar = StringVar()
self.spamCB = Checkbutton ( self, text="Spam?",
variable=self.spamVar, onvalue="yes", offvalue="no" )
If this checkbutton is on, self.spamVar.get() will return the string "yes"; if the
checkbutton is off, that same call will return the string "no". Furthermore, your
program can turn the checkbutton on by calling .set("yes").
You can also the textvariable option of a checkbutton to a StringVar. Then
you can change the text label on that checkbutton using the .set() method on that
variable.
Entry: Set its textvariable option to a StringVar. Use that variable’s .get()
method to retrieve the text currently displayed in the widget. You can also the
variable’s .set() method to change the text displayed in the widget.
Label: You can set its textvariable option to a StringVar. Then any call to
the variable’s .set() method will change the text displayed on the label. This is
not necessary if the label’s text is static; use the text attribute for labels that don’t
change while the application is running.
Menubutton: If you want to be able to change the text displayed on the menu
button, set its textvariable option to a StringVar() and use that variable’s
.set() method to change the displayed text.
Radiobutton: The variable option must be set to a control variable, either an
IntVar or a StringVar. All the radiobuttons in a functional group must share the
same control variable. Set the value option of each radiobutton in the group to a
different value. Whenever the user sets a radiobutton, the variable will be set to
the value option of that radiobutton, and all the other radiobuttons that share the
group will be cleared.