0
所以我想建立一個簡單的計算器顯示的數字PI即標籤3.14每一次按鍵「點擊我」被點擊它爲3.14添加了另一個十進制值。例如,一旦點擊該標籤將顯示3.141,第二次:3.1415等等等等如何更新標籤控件使用Tkinter的點擊每次按鈕 - Python的
下面是代碼:
# Import the Tkinter functions
from Tkinter import *
# Create a window
loan_window = Tk()
loan_window.geometry('{}x{}'.format(500, 100))
# Give the window a title
loan_window.title('Screeen!')
## create the counter
pi_num = 3.14
# NUMBER frame
frame = Frame(loan_window, width=100, height=50)
frame.pack()
def addPlaceValue():
pi_num= 3.14
return pi_num
## create a label and add it onto the frame
display_nums = Label(frame, text = 'pi_num')
display_nums.pack()
#### create a label and add it onto the frame
##display_nums = Label(frame, text = pi_num)
##display_nums.pack()
##
# Create a button which starts the calculation when pressed
b1 = Button(loan_window, text = 'Click me', command= addPlaceValue, takefocus = False)
b1.pack()
# Bind it
loan_window.bind('<Return>', addPlaceValue())
# event loop
loan_window.mainloop()
我試過很多次跟蹤按鈕點擊,但沒有這樣做。我看到一個問題;代碼不知道單擊哪一次按鈕。有任何想法嗎?