【问题标题】:I am writing a program on python, but window outupt none, but i need that it output ins我正在 python 上编写一个程序,但窗口没有输出,但我需要它输出 ins
【发布时间】:2022-01-02 16:47:12
【问题描述】:

我在 python 上写一个程序,但是窗口没有输出,但我需要它输出 ins 请帮助我,我是 python 新手 代码:

from typing import Text
import PySimpleGUI as sg
x = 'none'
z = 'none'
layout = [
   [sg.Text('Welcome')],
   [sg.Text('There you can install apps')],
   [sg.Button('hi', key='install')]
]

window = sg.Window('Apps Installer', layout)
layout2 = [
    [sg.Text(z)]
]
while True:                             # The Event Loop
    event, values = window.read()
    # print(event, values) #debug
    if event in ('install'):
        x = "steam"
        window = sg.Window('Apps Installer', layout2)
    else:
        break
if (x == 'steam'):
        z = 'ins'
layout2 = [
    [sg.Text(z)]
]

【问题讨论】:

  • 您似乎没有使用typing 模块; from typing import Text 对您的代码没有影响。
  • 它没有在描述或代码中告诉我们您在做什么。
  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: python pysimplegui


【解决方案1】:

如果没有问题,你的代码应该是这样的

import PySimpleGUI as sg

sg.theme("DarkBlue3")

x, z = 'none', 'none'

layout = [
   [sg.Text('Welcome')],
   [sg.Text('There you can install apps')],
   [sg.Button('hi', key='install')]
]

window = sg.Window('Apps Installer', layout)

while True:                             # The Event Loop
    event, values = window.read()
    # print(event, values) #debug
    if event in ('install', ):
        x = "steam"
        if x == "steam":
            z = "ins"
            sg.theme("LightBlue3")
            layout2 = [[sg.Text(z), sg.Button("OK")]]
            win = sg.Window('Apps Installer', layout2, modal=True)
            win.read(close=True)
    else:
        break

window.close()

【讨论】:

  • 你的代码和问题代码的主要区别是什么?只是sg.theme("...") 电话?这可能真的需要一些解释......
  • 不是使用的主题,主要区别在于子窗口的调用方式和事件循环中事件的处理方式。
猜你喜欢
  • 2021-10-05
  • 1970-01-01
  • 2019-12-23
  • 1970-01-01
  • 1970-01-01
  • 2020-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多