我正在制作一个可以打开循环的GUI,但是当我开始循环时,它不会自动运行。在这种情况下,它不会自动打印“测试”。我首先必须单击“检查变量”选项
我尝试上下移动代码,但这没用
# import tkinter
from tkinter import *
# 1 = on
# 3 = off
# Define Default variable
global x
x = 3
# Window preferences
root = Tk()
# Change Variables
def changeVar1():
global x
x = 1
def changeVar2():
global x
x = 3
def printVariable():
print(x)
# loop
while x < 2:
print ("Test")
# Buttons
button_1 = Button(root, text="Start", command=changeVar1)
button_2 = Button(root, text="End", command=changeVar2)
button_3 = Button(root, text="Check variable", command=printVariable)
# Button Posistion
button_1.pack()
button_2.pack()
button_3.pack()
root.mainloop()
答案 0 :(得分:0)
您需要使用after方法,并且不要在tkinker主循环内创建while循环,因为主循环会处理此问题。
= ^ .. ^ =
x = np.arange(100)
t = np.arange(100)
y = [p**2 for p in x]
source = pd.DataFrame({
't':t,
'x': x,
'f(x)': y
})
slider = alt.binding_range(min=int(min(t)), max=int(max(t)), step=1)
select_t = alt.selection_single(name="year", fields=['t'],
bind=slider, init={'year': 50})
alt.Chart(source).mark_line(point=True).encode(
alt.X('x',scale=alt.Scale(domain=(0,100))),
alt.Y('f(x)',scale=alt.Scale(domain=(0,10000)))
).add_selection(select_year).transform_filter(select_t)