我得到了框架的小部件串列frame.winfo_children()。現在我需要得到那個 checkbutton 的 value.Children List:
[<tkinter.Label 物件 .!toplevel2.!labelframe.!label>, <tkinter.Entry 物件 .!toplevel2.!labelframe.!entry>, <tkinter.Entry 物件 .!toplevel2.!labelframe.!entry2>, < tkinter.Checkbutton 物件 .!toplevel2.!labelframe.!checkbutton>]
我試過的:
checkbuttonwidget.get() , checkbuttonwidget.cget('variable')
我怎樣才能得到它的價值?是否有任何選項可以使用if命令來拆分這些孩子?例如:
for wid in frame.winfo_children():
if wid == LABEL(option?):
print('yes its a label')
elif wid == CheckButton(option?):
print('Its a CheckButton')
謝謝..
uj5u.com熱心網友回復:
檢查小部件是否為 a 的最簡單方法Checkbutton是使用isinstance,然后獲取值,您可以使用.getvar和widget['variable'](或widget.cget('variable')取決于您喜歡的方式)獲取相應變數的值:
for widget in frame.winfo_children():
if isinstance(widget, tk.Checkbutton):
value = frame.getvar(widget['variable'])
print(value)
還取決于您的匯入方式,您可能需要使用Checkbutton而不是tk.Checkbutton
有用:
isinstance檔案-
getvar(self, name='PY_VAR') Tcl 變數 NAME 的回傳值。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/352492.html
下一篇:串列框輸出Python
