Ai
4 Star 4 Fork 0

Gitee 极速下载/pysimplegui

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/PySimpleGUI/PySimpleGUI
克隆/下载
Demo_Button_States.py 2.94 KB
一键复制 编辑 原始数据 按行查看 历史
timkay@not.com 提交于 2024-02-12 23:14 +08:00 . First release of PySimpleGUI 5!
#!/usr/bin/env python
import PySimpleGUI as sg
"""
Demonstrates using a "tight" layout with a Dark theme.
Shows how button states can be controlled by a user application. The program manages the disabled/enabled
states for buttons and changes the text color to show greyed-out (disabled) buttons
Copyright 2023 PySimpleSoft, Inc. and/or its licensors. All rights reserved.
Redistribution, modification, or any other use of PySimpleGUI or any portion thereof is subject to the terms of the PySimpleGUI License Agreement available at https://eula.pysimplegui.com.
You may not redistribute, modify or otherwise use PySimpleGUI or its contents except pursuant to the PySimpleGUI License Agreement.
"""
sg.theme('Dark')
sg.set_options(element_padding=(0, 0))
layout = [[sg.Text('User:', pad=((3, 0), 0)), sg.OptionMenu(values=('User 1', 'User 2'), size=(20, 1)), sg.Text('0', size=(8, 1))],
[sg.Text('Customer:', pad=((3, 0), 0)), sg.OptionMenu(
values=('Customer 1', 'Customer 2'), size=(20, 1)), sg.Text('1', size=(8, 1))],
[sg.Text('Notes:', pad=((3, 0), 0)), sg.Input(size=(44, 1),
background_color='white', text_color='black')],
[sg.Button('Start', button_color=('white', 'black'), key='-Start-'),
sg.Button('Stop', button_color=('white', 'black'), key='-Stop-'),
sg.Button('Reset', button_color=('white', 'firebrick3'), key='-Reset-'),
sg.Button('Submit', button_color=('white', 'springgreen4'), key='-Submit-')]]
window = sg.Window("Time Tracker", layout,
default_element_size=(12, 1),
text_justification='r',
auto_size_text=False,
auto_size_buttons=False,
default_button_element_size=(12, 1),
finalize=True)
for key, state in {'-Start-': False, '-Stop-': True, '-Reset-': True, '-Submit-': True}.items():
window[key].update(disabled=state)
recording = have_data = False
while True:
event, values = window.read()
print(event)
if event == sg.WIN_CLOSED:
break
if event == '-Start-':
for key, state in {'-Start-': True, '-Stop-': False, '-Reset-': False, '-Submit-': True}.items():
window[key].update(disabled=state)
recording = True
elif event == '-Stop-' and recording:
[window[key].update(disabled=value) for key, value in {
'-Start-': False, '-Stop-': True, '-Reset-': False, '-Submit-': False}.items()]
recording = False
have_data = True
elif event == '-Reset-':
[window[key].update(disabled=value) for key, value in {
'-Start-': False, '-Stop-': True, '-Reset-': True, '-Submit-': True}.items()]
recording = False
have_data = False
elif event == '-Submit-' and have_data:
[window[key].update(disabled=value) for key, value in {
'-Start-': False, '-Stop-': True, '-Reset-': True, '-Submit-': False}.items()]
recording = False
window.close()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/mirrors/pysimplegui.git
git@gitee.com:mirrors/pysimplegui.git
mirrors
pysimplegui
pysimplegui
master

搜索帮助