Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

老师请问,怎么才能运行后,显示gui界面和访问网络两不误呢(运行后,gui标签的文字是从网络资源获取的)?
假如网络有点慢,gui内请求的网络内容,就会等网络加载完才显示…

gui使用的是pysimplegui
import PySimpleGUI as sg
import requests

sg.SetOptions(text_justification='center')
try:
    github = requests.get("http://baidu.com").status_code
    print(github)
except:
    github = '网络问题'

layout = [
    [
        sg.Button('退出'),
        sg.Text(
            github,
            size=(38, 1),
            key='git',
        ),
    ],
]

window = sg.Window('', layout, location=(450, 100))

while True:
    event, values = window.read()

    if event == '退出':
        break

window.close()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

使用多线程或者协程即可


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share
...