我是 python 的初学者并且正在使用 PySimpleGUI,但我一直收到此错误并且无法弄清楚原因。欢迎帮助...
错误是:
Traceback (most recent call last):
File "/Users/georgeknight/pythonProject/Metrics.py", line 17, in <module>
[tm_number], [sg.Column(col1)], [sg.Column(col2)],
File "/Users/georgeknight/pythonProject/venv/lib/python3.10/site-packages/PySimpleGUI/PySimpleGUI.py", line 7811, in __init__
self.Layout(layout)
File "/Users/georgeknight/pythonProject/venv/lib/python3.10/site-packages/PySimpleGUI/PySimpleGUI.py", line 7893, in layout
self.AddRow(*row)
File "/Users/georgeknight/pythonProject/venv/lib/python3.10/site-packages/PySimpleGUI/PySimpleGUI.py", line 7851, in add_row
if element.ParentContainer is not None:
AttributeError: 'tuple' object has no attribute 'ParentContainer'
这是我的代码:
import PySimpleGUI as sg
tm_number = sg.Text("Technical Manual Number:", font=(24,24)),
sg.Input(key='tm_number', font=(24,24), size=(48,24))
review = sg.Text("Type of Review:", font=(24,24)),
sg.Input(key='review', font=(24,24), size=(12,24))
pages = sg.Text("Number of Pages: ", font=(24,24)),
sg.Input(key='pages', font=(24,24), size=(6,24))
submission_date = sg.Text("Date of Submission: ", font=(24,24)),
sg.Input(key='submission_date', font=(24,24), size=(12,24))
writer = sg.Text("Writer's Name: ", font=(24,24)),
sg.Input(key='writer', font=(24,24), size=(24,24))
col1 = [[review], [submission_date]]
col2 = [[writer], [pages]]
layout = [[sg.Text("Writer's Submission Form", font=(48,48))],
[tm_number], [sg.Column(col1), sg.Column(col2)],
[sg.Button("SUBMIT FOR REVIEW", size=(24,1), font=24)]]
window = sg.Window("Technical Manual Engineering Review (TMER)", layout)
event, values = window.read()
window.close
我正在尝试构建一个简单的 GUI,顶部带有变量“tm_number”,然后是 2 列:一列带有变量“review”和“submission_date”,另一列带有“writer”和“pages”。该按钮应该位于窗口的右下角(还没有那么远)。
c = a, b # c = (a, b)
d = [c] # d = [(a, b)], not [a, b]
检查布局格式是否为
List[List[Element]] | Tuple[Tuple[Element]]
.
import PySimpleGUI as sg
tm_number = [sg.Text("Technical Manual Number:", font=(24,24)), sg.Input(key='tm_number', font=(24,24), size=(48,24))]
review = [sg.Text("Type of Review:", font=(24,24)), sg.Input(key='review', font=(24,24), size=(12,24))]
pages = [sg.Text("Number of Pages: ", font=(24,24)), sg.Input(key='pages', font=(24,24), size=(6,24))]
submission_date = [sg.Text("Date of Submission: ", font=(24,24)),sg.Input(key='submission_date', font=(24,24), size=(12,24))]
writer = [sg.Text("Writer's Name: ", font=(24,24)), sg.Input(key='writer', font=(24,24), size=(24,24))]
col1 = [review, submission_date]
col2 = [writer, pages]
layout = [
[sg.Text("Writer's Submission Form", font=(48,48))],
tm_number,
[sg.Column(col1), sg.Column(col2)],
[sg.Button("SUBMIT FOR REVIEW", size=(24,1), font=24)],
]
window = sg.Window("Technical Manual Engineering Review (TMER)", layout).read(close=True)