![](/img/trans.png)
[英]How do I print each element of list in a new line with pysimplegui?
[英]How do i use the value in a list, with combo - pysimplegui
import PySimpleGUI as sg
storedvals = []
sg.LOOK_AND_FEEL_TABLE['Theme'] = {'BACKGROUND': '#292929',
'TEXT': '#009bff',
'INPUT': '#ffffff',
'TEXT_INPUT': '#000000',
'SCROLL': '#ffffff',
'BUTTON': ('#5cfd46', '#151515'),
'PROGRESS': ('#01826B', '#D0D0D0'),
'BORDER': 1, 'SLIDER_DEPTH': 0, 'PROGRESS_DEPTH': 0,
}
sg.theme("Theme")
def mainmenu():
mainmenu = [
[sg.Text("Welcome to the Calculator!")],
[sg.Text("What would you like to do:")],
[sg.Text("1) Add\n2) Subtract\n3) Multiply\n4) Divide\n5) Exit")],
[sg.Text("Please enter the number of the option you would like!")],
[sg.InputText("", key="in1"),sg.Text("", key="answer")],
[sg.ReadButton("Submit")]
]
mainmenu = sg.Window('Window that stays open', mainmenu)
while True:
button, values = mainmenu.Read()
if button is None:
break
choice = int(values["in1"])
mainmenu.FindElement("answer").Update(choice)
if choice == 1:
mainmenu.Close()
add()
if choice == 2:
mainmenu.Close()
subtract()
if choice == 3:
mainmenu.Close()
multiply()
if choice ==4:
mainmenu.Close()
divide()
if choice == 5:
exit()
def add():
add = [
[sg.Text("What numbers would you like to add together?")],
[sg.Text("Stored values are in the drop down option!")],
[sg.Combo([storedvals], size=(5,1), key="num1"), sg.Text("+"), sg.Combo([storedvals], size=(5,1), key="num2")],
[sg.Text("Do you want to store this value")],
[sg.Radio("Yes", "1", key="x"), sg.Radio("No", "1",)],
[sg.ReadButton("Add")],
[sg.Text("Answer:"), sg.Text("", size=(10,1), key="answer")],
[sg.Button("Return to the menu"), sg.Exit()],
]
add = sg.Window("", add)
while True:
button, values = add.Read()
if button is None:
break
num1 = int(values["num1"])
num2 = int(values["num2"])
answer = num1 + num2
add.FindElement("answer").Update(answer)
x = values["x"]
if x == 1:
storedvals.append(answer)
sg.Popup("You answer has been stored in position", storedvals.index(answer))
print(storedvals)
event, values = add.Read()
if event == "Return to the menu":
add.Close()
mainmenu()
mainmenu()
这是我的代码。 该子程序完成后,可以返回主菜单再次使用计算器。 我想要它,以便他们可以存储以前的计算答案,然后选择在以后的计算中使用它(有效)。 我选择使用组合,但是,我收到一个错误,在研究了错误后,我找不到问题的修复/解决方法。 任何提示都是有帮助的。
The error: TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'
我尝试了多种不同的方法来尝试操作它,但我刚刚开始学习pysimple
GUI,所以我被卡住了。
解决方案是添加element.update(values=answer)
,其中 answer 应该添加一个完整的列表,而不仅仅是一个条目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.