我无法在浏览器上获得任何输出



这段代码计算用户在给定日期的位移。3班制(早、中、晚),每5周轮换一次。每班有两组技术人员。1队在太阳-星期四轮换,2队在星期二-星期六轮换

为了使代码更加用户友好,已经用PySimpleGUI实现了GUI。我尝试使用PySipmleGUIWeb在我的web浏览器中运行此程序。

在浏览器中启动应用程序,我选择日期,shift等没有问题。一旦我点击提交按钮,实际上什么也没有发生,我在Pycharm控制台中得到以下输出:

Returned from Remi Start command... now sending None event

试图摆脱弹出窗口的结果,并试图只是打印它们。我没有得到任何错误,但只有PyCharm控制台而不是web浏览器的结果。

关于如何使用PySimpleGUIWeb使此工作的任何想法?

提前谢谢你。

import datetime
import math
import calendar
import PySimpleGUIWeb as sg
import traceback
layout = [
[sg.Text("Please enter your Current Shift and the date you would like to check what rotation you will be.")],
[sg.Text("Current Shift", size=(15, 1)), sg.Checkbox("Morning", key="morning"), sg.Checkbox("Evening", key="evening"), sg.Checkbox("Night", key="night")],
[sg.Text("First day Off", size=(15, 1)), sg.Combo(["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], key="Day_Off")],
[sg.Text("Date YYYY.MM.DD", size=(18, 1)), sg.InputText("Date in YYYY.MM.DD format", key="Date")],
[sg.Submit(), sg.Cancel()]
]
window = sg.Window("Shift Rotation", layout=layout, background_color="#272533", size=(600, 150), web_start_browser=True)
try:
while True:
event, values = window.read()
window.close()
if event is None:
break
if event == "Cancel":
break
if event == "Submit":
def Days_Off():
week = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]
Dayoff2 = week[week.index(Dayoff1.lower())+1]
DayOffCheck = calendar.day_name[date1.weekday()]
if Dayoff1.lower() == DayOffCheck.lower() or Dayoff2.lower() == DayOffCheck.lower():
sg.popup("Hey it is {}! You got the day off!".format(DayOffCheck))
else:
sg.popup("It is {}! You are working on that day!".format(DayOffCheck))
def Morning():
Morning = []
Evening = []
Night = []
x = 1
y = 2
z = 3
for i in range(99999):
Morning.append(float(x + 3 * i))
Evening.append(float(y + 3 * i))
Night.append(float(z + 3 * i))
if ShiftC in Morning:
sg.popup("You will be on Morning shift at requested date: {}".format(date_entry))
elif ShiftC in Evening:
sg.popup("You will be on Evening shift at requested date: {}".format(date_entry))
elif ShiftC in Night:
sg.popup("You will be on Night shift at requested date: {}".format(date_entry))

def Evening():
Evening = []
Night = []
Morning = []
x=1
y=2
z=3
for i in range(99999):
Evening.append(float(x+3*i))
Night.append(float(y+3*i))
Morning.append(float(z+3*i))
if ShiftC in Morning:
sg.popup("You will be on Morning shift at requested date: {}".format(date_entry))
elif ShiftC in Evening:
sg.popup("You will be on Evening shift at requested date: {}".format(date_entry))
elif ShiftC in Night:
sg.popup("You will be on Night shift at requested date: {}".format(date_entry))
def Night():
x = 1
y = 2
z = 3
Night = [x]
Morning = [y]
Evening = [z]
for i in range(1, 99999):
Night.append(int(x + 3 * i))
Morning.append(int(y + 3 * i))
Evening.append(int(z + 3 * i))
if ShiftC in Morning:
sg.popup("You will be on Morning shift at requested date: {}".format(date_entry))
elif ShiftC in Evening:
sg.popup("You will be on Evening shift at requested date: {}".format(date_entry))
elif ShiftC in Night:
sg.popup("You will be on Night shift at requested date: {}".format(date_entry))
if values["morning"] == True:
SelectShift = "morning"
elif values["evening"] == True:
SelectShift = "evening"
elif values["night"] == True:
SelectShift = "night"
date_entry = values["Date"]
Dayoff1 = values["Day_Off"]
year, month, day = map(int, date_entry.split('.'))
date1 = datetime.date(year, month, day)
TotalD = (datetime.date(2021, 1, 9).toordinal() - date1.toordinal()) * -1
ShiftC = math.ceil(TotalD / 35)
if SelectShift.lower() == "morning":
Morning()
Days_Off()
elif SelectShift.lower() == "evening":
Evening()
Days_Off()
elif SelectShift.lower() == "night":
Night()
Days_Off()
except Exception as e:
tb = traceback.format_exc()
sg.Print(f'An error happened.  Here is the info:', e, tb)
sg.popup_error(f'AN EXCEPTION OCCURRED!', e, tb)

问题是

window.close()

用于第24行。把它移到第111行,现在效果很好。

最新更新