有问题尝试使用真棒Appjar package获取线程在python中的工作。python appjar函数不会线程
以下程序需要通过列表进行计数,并同时更新进度条。我跟着appjar documentation for threading,但它的返回NameError: name 'percent_complete' is not defined
在app.thread
(35行),在你打算插入功能PARAMS - 我的代码如下:
from appJar import gui
import time
# define method the counts through a list of numbers, and updates the progress meter
def press(btn):
objects = [1,3,6]
total = len(objects)
current_object = 0
for i in objects:
print(i)
current_object += 1
current_percent_complete = (current_object/total) * 100
updateMeter(current_percent_complete)
time.sleep(1)
def updateMeter(percent_complete):
app.queueFunction(app.setMeter, "progress", percent_complete)
# create a GUI variable called app
app = gui("Login Window")
app.setBg("orange")
app.setFont(18)
# add GUI elements : a label, a meter, & a button
app.addLabel("title", "COUNTER")
app.setLabelBg("title", "blue")
app.setLabelFg("title", "orange")
app.addMeter("progress")
app.setMeterFill("progress", "green")
app.addButton("START COUNTING", press)
# put the updateMeter function in its own thread
app.thread(updateMeter, percent_complete)
# start the GUI
app.go()
我可以摆脱错误的定义percent_complete
像这样:
from appJar import gui
import time
# define method the counts through a list of numbers, and updates the progress meter
percent_complete = 0
def press(btn):
...
然而,当GUI负载和按钮被按下不线程。相反,它遍历列表,然后更新进度条。
有没有人遇到过同样的问题?任何洞察力将非常感激! 谢谢!