Python知識(shí)分享網(wǎng) - 專業(yè)的Python學(xué)習(xí)網(wǎng)站 學(xué)Python,上Python222
tkinter_nmt PDF 下載
匿名網(wǎng)友發(fā)布于:2024-08-14 11:52:45
(侵權(quán)舉報(bào))
(假如點(diǎn)擊沒反應(yīng),多刷新兩次就OK!)

tkinter_nmt PDF 下載 圖1

 

 

資料內(nèi)容:

 

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.