亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在Python中將StringVar()作為普通字符串訪問

在Python中將StringVar()作為普通字符串訪問

狐的傳說 2021-04-06 17:19:45
我想訪問選定的單選按鈕的值,并將其與if語句進行比較,但是在訪問該值時,我得到的是PY_VAR0。from tkinter import *ComplaintForm=Tk()typesel=StringVar()#<--variable I'm using to access value of selected RadiobuttonHighVoltage=Radiobutton(ComplaintForm,text='High Voltage Motor',value='HighVoltage',\                      anchor=W,font='roboto 18',bg='white',variable=typesel)HighVoltage.grid(row=5,column=1,padx=5,pady=10)LowVoltage=Radiobutton(ComplaintForm,text='Low Voltage Motor',value='LowVoltage',\                      anchor=W,font='roboto 18',bg='white',variable=typesel)LowVoltage.grid(row=5,column=0,padx=5,pady=10)print(typesel)#this is printing PY_VAR0 instead of accessing value of above Radiobuttonsmainloop()PS:我知道此代碼中引入了一些弊端,以使代碼保持最小化,并使問題易于理解。
查看完整描述

1 回答

?
紫衣仙女

TA貢獻1839條經驗 獲得超15個贊

您可以訪問Tkinter的變量的值類BooleanVar,DoubleVar,IntVar,或者StringVar是這樣的:


my_variable = tk.StringVar()

my_variable.set('value')

print(my_variable.get())   # <-- returns and prints the value contained in my_variable


查看完整回答
反對 回復 2021-04-20
  • 1 回答
  • 0 關注
  • 1171 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號