在我的应用程序中,我试图将我的按钮、文本和输入放在窗口的中心。我正在使用 PySimpleGUI 来设计按钮。为了与中心对齐,我在我的代码中使用了 justification='center'
属性。但仍然如此不适合窗口的中心。
正在使用的代码是
import PySimpleGUI as sg
from tkinter import *
sg.theme('DarkAmber')
layout = [
[sg.Text('Enter the value',justification='center')],
[sg.Input(justification='center')],
[sg.Button('Enter','center')]
]
window = sg.Window('My new window', layout, size=(500,300), grab_anywhere=True)
while True:
event, values = window.read() # Read the event that happened and the values dictionary
print(event, values)
if event == sg.WIN_CLOSED or event == 'Exit': # If user closed window with X or if user clicked "Exit" button then exit
break
if event == 'Button':
print('You pressed the button')
window.close()
原文由 Avinash Babu 发布,翻译遵循 CC BY-SA 4.0 许可协议
此代码使文本、按钮和输入位于窗口的中心。