我在程序中做了一个多进程。想要在多进程中操作变量(progress_bar_var)这个是显示多进程状态的变量。但是为知道为什么只要对这个变量进行操作。多进程就会死在这里面。不操作没有问题。progress_bar_var这个变量是一个 StringVar()变量 联接到界面程序里面的一个控件上的。这个变量申明为全局变量也不行。这是什么原因。谢谢
from tkinter import *
import time
import threading
def show():
global n
progress_bar_var.set(n)
def select_file():
global n
for i in range(10):
time.sleep(1)
mutex.acquire()
n = n+1
mutex.release()
show()
def two():
global n
pp=[]
n=50
for i in range(10):
t = threading.Thread(target=select_file) #
pp.append(t)
t.start()
for p in pp:
p.join()
if name == 'main':
mutex = threading.Lock()
n = 1
t=threading.Timer(1, show)
root = Tk()
root.geometry('400x200') # 这里的乘号不是 * ,而是小写英文字母 x
top = 5
progress_bar_var = StringVar()
Label(root, text="进度", height=1, width=26,
textvariable=progress_bar_var,
background="yellow", font=('宋体', 15)).place(x=60, y=top)
Button(root, text="测试", height=2, width=5,
command=two,
background="yellow",
font=('宋体', 12)).place(x=340, y=top - 4)
root.mainloop()