には、Appjar packageを使用してPythonでスレッドを処理しようとする問題がありません。python appjar関数はスレッド
次のプログラムは、リストをカウントし、進行状況バーを同時に更新する必要があります。私はappjar documentation for threadingに従ってきましたが、それはあなたが関数のparamsを挿入することを意図しているここでapp.thread
(ライン35)、中NameError: name 'percent_complete' is not defined
を返すだ - 私のコードは以下の通りです:私はしてエラーを取り除くことができます
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()
しかし
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負荷とボタンが押されたとき、それはスレッドはありません。そうのようなpercent_complete
を定義します。その代わりに、リストを反復して、その後、進行状況バーを更新します。
誰もが同じ問題を抱えていますか?どんな洞察もすごく感謝しています! ありがとう!