Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

python运行后,显示gui界面和访问网络如何两不误

老师请问,怎么才能运行后,显示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()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

使用多线程或者协程即可


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...