PySimpleGui 表行单击事件
python的新手并在学生得分管理系统上进行学校项目。
我想在单击表行时更新右窗口上的文本以与学生的名字相对应。
我应该在活动循环中添加什么才能实现这一目标?
import PySimpleGUI as sg
nameDict = {'A1': 'Albedo',
'A2': 'Barbara',
'A3': 'Chongyun',
'A4': 'Diluc',
'A5': 'Eula',
'A6': 'Fischl',
'A7': 'Ganyu',
'A8': 'Hu Tao',
'A9': 'Jean',
'A10': 'Kazuha'}
nameList = [[1, nameDict["A1"], 3.5],
[2, nameDict["A2"], 3.5],
[3, nameDict["A3"], 3.5],
[4, nameDict["A4"], 3.5],
[5, nameDict["A5"], 3.5],
[6, nameDict["A6"], 3.5],
[7, nameDict["A7"], 3.5],
[8, nameDict["A8"], 3.5],
[9, nameDict["A9"], 3.5],
[10, nameDict["A10"], 3.5]]
headings = ['Index', 'Name', 'Cumulative GPA']
activeStudent = [
[sg.Text("Name:"),sg.Text('',enable_events=True,key='-activeStudent-')],
[sg.Text("Math Result:"), sg.Text('', enable_events=True, key='-math-')],
[sg.Text("English Result:"), sg.Text('', enable_events=True, key='-english-')],
[sg.Text("Science Result:"), sg.Text('', enable_events=True, key='-science-')],
]
result = [
[sg.Table(values=nameList, headings=headings, max_col_width=100,
auto_size_columns=True,
display_row_numbers=False,
justification='center',
num_rows=10,
key='hello',
row_height=55,
tooltip='Results',
enable_click_events=True),sg.Frame('',activeStudent,size=(800,550))],
]
resultsWindow = sg.Window("Register Results", result, size=(1000, 500), finalize=True, )
while True:
event, values = resultsWindow.read()
if event == "Submit" or event == sg.WIN_CLOSED:
break
New to python and doing a school project on student score management system.
I want to update the text on the right window to correspond with the student's name when I click the table row.
What should I add to my event loop to achieve that?
import PySimpleGUI as sg
nameDict = {'A1': 'Albedo',
'A2': 'Barbara',
'A3': 'Chongyun',
'A4': 'Diluc',
'A5': 'Eula',
'A6': 'Fischl',
'A7': 'Ganyu',
'A8': 'Hu Tao',
'A9': 'Jean',
'A10': 'Kazuha'}
nameList = [[1, nameDict["A1"], 3.5],
[2, nameDict["A2"], 3.5],
[3, nameDict["A3"], 3.5],
[4, nameDict["A4"], 3.5],
[5, nameDict["A5"], 3.5],
[6, nameDict["A6"], 3.5],
[7, nameDict["A7"], 3.5],
[8, nameDict["A8"], 3.5],
[9, nameDict["A9"], 3.5],
[10, nameDict["A10"], 3.5]]
headings = ['Index', 'Name', 'Cumulative GPA']
activeStudent = [
[sg.Text("Name:"),sg.Text('',enable_events=True,key='-activeStudent-')],
[sg.Text("Math Result:"), sg.Text('', enable_events=True, key='-math-')],
[sg.Text("English Result:"), sg.Text('', enable_events=True, key='-english-')],
[sg.Text("Science Result:"), sg.Text('', enable_events=True, key='-science-')],
]
result = [
[sg.Table(values=nameList, headings=headings, max_col_width=100,
auto_size_columns=True,
display_row_numbers=False,
justification='center',
num_rows=10,
key='hello',
row_height=55,
tooltip='Results',
enable_click_events=True),sg.Frame('',activeStudent,size=(800,550))],
]
resultsWindow = sg.Window("Register Results", result, size=(1000, 500), finalize=True, )
while True:
event, values = resultsWindow.read()
if event == "Submit" or event == sg.WIN_CLOSED:
break
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为,您的第一个问题是在 sg.table 上,而不是
:
这样,您可以捕获事件 hello ,您将获得元素您想要这样的东西:
现在,它已经写在上面的代码中,但是要更新SG.Frame以这种方式进行:
您必须根据要更新的内容更改-Key-。
我用于测试的整个代码:
祝您好运。
i think, the first of your problem is on the sg.table instead of
it should be:
in that way, you can catch the event hello and you will get the elements you want something like this:
now, it is already written in the above code, but to update the sg.frame do it this way:
you will have to change the -key- according what you want to update.
the whole code i used for testing:
good luck.