在 PySimpleGUI 中更新值
Updating Values in PySimpleGUI
我有一个通过 selenium 从网站获取数据的机器人,我想在 GUI 上绘制该数据。 Bot 也发送电子邮件和通知,我需要以某种方式随时更改 real_email
和 real_noti
Live 的值。
整个 BOT 代码在一个 while True:
循环中。
我现在遇到的问题是,我正在考虑在同一个 while
循环中添加我的 BOT CODE 和 pysimplegui,但程序在 event, values = window.read()
处停止输入并且不会继续输入已通过。
这是演示代码。
import PySimpleGUI as sg
sg.theme('DarkAmber') # Keep things interesting for your users
elem = sg.Text('Email and Notfication ON', key='-TEXT-')
layout = [[elem],
[sg.Input(key='-IN-')],
[sg.Input(key='-IN')],
[sg.Button('Ok'), sg.Exit()]]
window = sg.Window('Window that stays open', layout)
real_email = "On"
real_noti = "On"
while True: # The Event Loop
event, values = window.read()
email = values['-IN-']
notification = values['-IN']
if email == "On":
real_email = "On"
elif email == "Off":
real_email = "Off"
if notification == "On":
real_noti = "On"
elif notification =="Off":
real_noti = "Off"
if event in (None, 'Exit'):
break
print("Testing Print Value After .read()")
window.close()
我只想在此循环中更改这两个值。也许是使用复选框或仅按钮的方法?
您必须在 sg.Input(key='-IN-')
中设置 enable_event=True
将是 sg.Input(key='-IN-', enable_event=True)
我有一个通过 selenium 从网站获取数据的机器人,我想在 GUI 上绘制该数据。 Bot 也发送电子邮件和通知,我需要以某种方式随时更改 real_email
和 real_noti
Live 的值。
整个 BOT 代码在一个 while True:
循环中。
我现在遇到的问题是,我正在考虑在同一个 while
循环中添加我的 BOT CODE 和 pysimplegui,但程序在 event, values = window.read()
处停止输入并且不会继续输入已通过。
这是演示代码。
import PySimpleGUI as sg
sg.theme('DarkAmber') # Keep things interesting for your users
elem = sg.Text('Email and Notfication ON', key='-TEXT-')
layout = [[elem],
[sg.Input(key='-IN-')],
[sg.Input(key='-IN')],
[sg.Button('Ok'), sg.Exit()]]
window = sg.Window('Window that stays open', layout)
real_email = "On"
real_noti = "On"
while True: # The Event Loop
event, values = window.read()
email = values['-IN-']
notification = values['-IN']
if email == "On":
real_email = "On"
elif email == "Off":
real_email = "Off"
if notification == "On":
real_noti = "On"
elif notification =="Off":
real_noti = "Off"
if event in (None, 'Exit'):
break
print("Testing Print Value After .read()")
window.close()
我只想在此循环中更改这两个值。也许是使用复选框或仅按钮的方法?
您必须在 sg.Input(key='-IN-')
中设置 enable_event=True
将是 sg.Input(key='-IN-', enable_event=True)