import tkinter as tk
import time
import random
def whatever():
shijian = time.clock()
neirong = '已运行:{:.0f}秒'.format(shijian)
wucha = round(shijian, 3) - round(shijian)
dengdai = int((1 - wucha) * 1000)
shijian_weizhi.configure(text=neirong)
shijian_weizhi.after(dengdai, whatever)
def yes_whatever():
global x, y, z, b
a = random.uniform(0.5, 3.5)
if a < 2:
x += random.uniform(0.1, 1)
z = x / y
if z <= 1:
neirong = '已加载:{:.2f}%'.format(z*100)
else:
neirong = '已加载:100%'
jincheng_weizhi.config(text=neirong)
jincheng_weizhi.after(' ', yes_whatever)
if b:
exit()
if z > 1:
b = True
chuangkou = tk.Tk()
chuangkou.geometry('720x480')
shijian_weizhi = tk.Message(chuangkou)
shijian_weizhi.pack()
jincheng_weizhi = tk.Label(chuangkou, text='啥都没有')
jincheng_weizhi.place(x=100, y=100)
x = 0
y = 10
z = x / y
b = False
whatever()
yes_whatever()
chuangkou.mainloop()
我知道改成下面这样可以运行,但我想知道报错里那几种形式怎么改vimport tkinter as tk
import time
import random
def whatever():
shijian = time.clock()
neirong = '已运行:{:.0f}秒'.format(shijian)
wucha = round(shijian, 3) - round(shijian)
dengdai = int((1 - wucha) * 1000)
shijian_weizhi.configure(text=neirong)
shijian_weizhi.after(dengdai, whatever)
def yes_whatever():
global x, y, z, b
a = random.uniform(0.5, 3.5)
if a < 2:
x += random.uniform(0.1, 1)
z = x / y
if z <= 1:
neirong = '已加载:{:.2f}%'.format(z*100)
else:
neirong = '已加载:100%'
jincheng_weizhi.config(text=neirong)
jincheng_weizhi.after(500, yes_whatever)
if b:
exit()
if z > 1:
b = True
chuangkou = tk.Tk()
chuangkou.geometry('720x480')
shijian_weizhi = tk.Message(chuangkou)
shijian_weizhi.pack()
jincheng_weizhi = tk.Label(chuangkou, text='啥都没有')
jincheng_weizhi.place(x=100, y=100)
x = 0
y = 10
z = x / y
b = False
whatever()
yes_whatever()
chuangkou.mainloop()
|