【问题标题】:PySimpleGUI returning nonePySimpleGUI 不返回任何内容
【发布时间】:2020-08-03 03:12:00
【问题描述】:

当我执行这段代码时,我不明白为什么在我按下后退按钮后它给出了一个无。这段代码的主要目的是从一个窗口切换到另一个窗口。

import PySimpleGUI as sg
 
class Canvas:
    
    def __init__(self):
        buttons=[['Safe', 'Env', 'Health', 'Quali'],
        ['Forms','Checklist','Photos','Back']
              ]
        #Layout
        lt = [[sg.Button(i)] for i in buttons[0]]
        lt2 = [[sg.Button(i)] for i in buttons[1]]
        #Janela
        self.windows = [sg.Window('A').Layout(lt),sg.Window('S').Layout(lt2)]

    def Begin(self):
        i=0
        while True:
            self.event, self.values = self.windows[i].Read()
         
            #When pressing the button, changing the window
            if self.event == 'Safe':
                self.windows[i].Close() 
                i=1
            if self.event == 'Back':
                i=0
            #Closing part
            if self.event in (None, 'Exit'):
                break

cv = Canvas()
cv.Begin()

【问题讨论】:

    标签: button pysimplegui


    【解决方案1】:

    这可能对你有用:

    import PySimpleGUI as sg
     
    class Canvas:
        
        def __init__(self):
            self.buttons=[['Safe', 'Env', 'Health', 'Quali'],
            ['Forms','Checklist','Photos','Back']
                  ]
            #Layout
            self.lt = [[sg.Button(i)] for i in self.buttons[0]]
            #Janela
    
        def Begin(self):
            self.windows = sg.Window('A').Layout(self.lt)
            while True:
                self.event, self.values = self.windows.Read()
                #When pressing the button, changing the window
                if self.event == 'Safe':
                    self.windows.Disappear()
                    self.lt2 = [[sg.Button(i)] for i in self.buttons[1]]
                    self.windows1 = sg.Window('S').Layout(self.lt2)
                    while True:
                        self.event1, self.values1 = self.windows1.Read()
                        if self.event1 == 'Back':
                            self.windows1.close()
                            break
                        if self.event in (None, 'Exit'):
                            break
                    self.windows.reappear()
                #Closing part
                if self.event in (None, 'Exit'):
                    break
    
    cv = Canvas()
    cv.Begin()
    

    【讨论】:

      猜你喜欢
      • 2020-04-27
      • 2019-04-06
      • 2012-02-15
      • 2020-09-07
      • 2021-11-22
      • 2015-11-06
      • 2013-11-14
      • 2014-03-23
      • 2012-08-25
      相关资源
      最近更新 更多