大家好,我目前正在 python 中處理 rpg 動態字符表,我主要使用 tkinter 庫,但我遇到了阻礙我繼續前進的障礙。
我想要實作的是從旋轉框(稱為con和vol)中獲取兩個數字,這些數字可以從 1 到 10 不等,并將這兩個數字進行比較以實時顯示terre旋轉框旁邊標簽 ( )上的最低數字。例如,如果con等于 2 且vol等于 3,terre則應顯示 2,如果con添加 1,則將terre等于 3,因為con= 3 和vol= 3 依此類推。
我遇到的問題是它terre似乎沒有連接con并且vol沒有正確更新,當我更改兩個變數的旋轉框中的數字時,terre保持不變(即 0)并且不會讓步。
到目前為止,我的腳本如下(對不起,如果它看起來不好,我對編程仍然很陌生):
def Terre_calcul(*args) :
tr1 = int(con.get())
tr2 = int(vol.get())
if tr1 > tr2 :
terreV.set(vol.get())
else :
terreV.set(con.get())
#################################
#creation of the parent widget
win = Tk()
win.title("Fiche personnage")
#widgets dimensions
win.geometry("800x1029 0 0")
win.resizable(width= False, height= False)
##################################
#Constitution
con = IntVar()
conE = Spinbox(win, from_= 1, to= 10, width= 1, textvariable= con)
conE.place(x= 180, y= 165)
con.set(conE.get())
#Volonté
vol = IntVar()
volE = Spinbox(win, from_= 1, to= 10, width= 1, textvariable= vol)
volE.place(x= 168, y= 196)
vol.set(volE.get())
#Score
terreV = IntVar()
terre = Label(win, textvariable= terreV)
terre.tkraise(aboveThis= None)
terre.place(x= 266, y= 212)
win.mainloop()
忽略一些法語胡言亂語,這真的不重要。我很樂意回答任何進一步的問題,我希望你能幫助我解決這個問題,在此先感謝你:)。
uj5u.com熱心網友回復:
您可以分配Terre_calcul給command兩個旋轉框的選項:
...
conE = Spinbox(win, from_= 1, to= 10, width= 5, textvariable= con, command=Terre_calcul)
...
volE = Spinbox(win, from_= 1, to= 10, width= 5, textvariable= vol, command=Terre_calcul)
...
Terre_calcul() # update terreV initially
win.mainloop()
然后,每當旋轉框之一的值發生更改時,Terre_calcul()都會執行。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/327493.html
上一篇:繼承類回傳NoneType實體
