在我的代码中,我试图制作一个计算器。因此,有一个1
按钮,当按下该按钮时,通过向其文本中添加1
来更新Question:
文本。因此,当我按下1
时,文本将从Question:
转换为Question: 1
。但它并没有更新。我以前也遇到过这个问题。我想当我做.update
时,它只会更新值,直到它的字母数与文本的字母数相同为止。如果它有两个字母,我尝试.update('123')
,它将只更新为12
。有没有办法绕过这个问题
import PySimpleGUI as sg
layout = [
[sg.Text('Question: ', key='-IN-')],
[sg.Text('Answer will be shown here', key='-OUT-')],
[sg.Button('1'), sg.Button('2'), sg.Button('3')],
[sg.Button('4'), sg.Button('5'), sg.Button('6')],
[sg.Button('7'), sg.Button('8'), sg.Button('9')],
[sg.Button('Enter'), sg.Button('Exit')]
]
window = sg.Window('calculator', layout)
while True:
event, values = window.read()
if event is None or event == 'Exit':
break
elif event == '1':
bleh = window['-IN-'].get()
teh = f'{bleh}1'
window['-IN-'].update(value=teh)
window.close()
正如上面的评论,像这样的例子
相关问题 更多 >
编程相关推荐