【问题标题】:I am not able to get any output on the browserPySimpleGUI - 我无法在浏览器上获得任何输出
【发布时间】:2021-05-13 13:12:32
【问题描述】:

这段代码计算用户在给定日期的班次。 3 x 班次(早、晚、晚)每 5 周轮换一次。每个班次都有 2 个技术团队。第 1 队进行周日至周四轮换工作 第 2 队进行周二至周六轮换工作

使用 PySimpleGUI 实现了一个 GUI,以使代码更加用户友好。 我尝试使用 PySipmleGUIWeb 在我的网络浏览器中运行它。

在浏览器中启动应用程序时,我可以毫无问题地选择日期、班次等。只要我点击提交按钮,实际上什么都没有发生,我在 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)
  

【问题讨论】:

    标签: python web browser output pysimplegui


    【解决方案1】:

    问题是

    window.close()
    

    在第 24 行使用。将它移到第 111 行,现在这就像一个魅力。

    【讨论】:

      猜你喜欢
      • 2021-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-09
      相关资源
      最近更新 更多