pysimpleguie-Python
我想要一些帮助 我正在接受有关此代码的培训:pysimpleguie-Python,python,pysimplegui,Python,Pysimplegui,我想要一些帮助 我正在接受有关此代码的培训: import PySimpleGUI as sg category = ['Smartphone', 'Battery', 'Charger'] brand = ['Iphone', 'Motorola', 'LG'] color = ['White', 'Green', 'Black'] size_font = 20 layout = [[sg.Text('Code', font=size_fon
import PySimpleGUI as sg
category = ['Smartphone', 'Battery', 'Charger']
brand = ['Iphone', 'Motorola', 'LG']
color = ['White', 'Green', 'Black']
size_font = 20
layout = [[sg.Text('Code', font=size_font), sg.Input(key='-COD-', font=size_font, size=(20, 1))],
[sg.Text('Un', font=size_font), sg.InputText(key='-UN-', font=size_font, size=(10, 1))],
[sg.Text('Name', font=size_font), sg.Input(key='-NAME-', size=(30, 1))],
[sg.Text('Category', font=size_font), sg.Combo(category, font=size_font, key='-CATEG-', size=(30, 1))],
[sg.Text('Brand', font=size_font), sg.Combo(marca, font=size_font, key='-BRAND-')],
[sg.Text('Color', font=size_font), sg.Combo(color, font=size_font, key='-COL-')],
[sg.Text('')],
[sg.Button('Insert', font=size_font), sg.Button('Cancel', font=size_font)]]
window = sg.Window('Product Registration', layout, size=(700, 300))
while True:
event, values = window.read()
if event in (sg.WIN_CLOSED, 'Cancel'):
break
if event == 'Insert':
window['-NAME-'].update(window['-CATEG-'])
window.close()
我希望在组合列表中选择的值,其键为='-CATEG-',填充为key='-NAME-'。但对象正在返回,而不是所选的值,例如:。
还有一件事:你能把键连接起来吗?'-CATEG-'+'-BRAND-'+'-COLOR-'这个连接点放在key='-NAME-'中?。示例:在“类别”组合中,选择了智能手机选项;在“品牌,摩托罗拉”和“颜色”,黑色。因此,“名称”字段应为:智能手机摩托罗拉黑色
此外,创建变量来定义一些参数是一种很好的做法,就像对变量“size\u font”所做的那样?我这样认为是因为我相信维护会更容易
值[键]
,而不是窗口[键]
window['-NAME-']。更新(值['-CATEG-'])
str.join
连接所有字符串text=''.join([值['-CATEG-']、值['-BRAND-']、值['-COLOR-']))
窗口['-NAME-']。更新(文本)
size\u font=(“Courier New”,20)
sg.设置选项(字体=大小字体)