小编Mr.*_*eus的帖子

如何使while(True):在python中同时运行两个循环

基本上我需要同时运行两个 while 循环。原因是我需要一个循环来更新 GUI,另一个循环来检查程序是否连接到互联网。所以也许这需要多线程,或者也许我只需要一个网页就可以解决我的问题。这是我的源代码:

# -*- coding: utf-8 -*-

import sys
import urllib2
from Tkinter import *
import time
import socket

def TheMainProgram():
    airid = 'http://www.aviationweather.gov/metar/data?ids={airid}&format=raw&hours=0&taf=off&layout=off&date=0'.format(airid=e1.get())
    website = urllib2.urlopen(airid)
    website_html = website.read()
    data_start = website_html.find("<!-- Data starts here -->")
    br1 = data_start + 25
    br2 = website_html.find("<br />")
    metar_slice = website_html[br1:br2]
    print("Here is the undecoded METAR data:\n"+metar_slice)
    root2 = Tk()
    root2.title("#Conection_Made#")
    metar_dat_label = Label(root2, text="Here is the undecoded METAR data:")
    metar_dat_label_ln_2 = Label(root2, text=metar_slice)
    metar_dat_label.grid(row=0)
    metar_dat_label_ln_2.grid(row=1)    


def _quit():
    sys.exit()

def …
Run Code Online (Sandbox Code Playgroud)

python multithreading tkinter urllib2 python-3.x

1
推荐指数
1
解决办法
8591
查看次数

标签 统计

multithreading ×1

python ×1

python-3.x ×1

tkinter ×1

urllib2 ×1