如何在python程序和tkinter窗口之间链接Progressbar?

2024-04-29 20:52:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我在一个文件夹中有两个.py文件(Main_程序.py以及人机界面.py). 第一个是一个代码,它包含一个大循环(递增),开头有一个打印,显示代码执行的演变(10%,20%等)。第二个文件是一个接口,它包含一个执行Main命令的按钮_程序.py. 我想在我的界面中创建一个Progressbar,它将链接到第一个代码中打印的演变。但我们该怎么做呢?非常感谢你。你知道吗

你知道吗人机界面.py地址:

import tkinter
from tkinter import *
from tkinter import ttk
from Main_program import run_progessbar
...
root = Tk()
...
jj=0
progessBar = ttk.Progressbar(root, orient="horizontal",length=170,
                             style='black.Horizontal.TProgressbar',
                             mode='determinate', variable=jj)
progessBar.place(x=1060,y=180
...

主要_程序.py地址:

def run_progessbar():
    import numpy as np
    import matplotlib
    ...
    global jj  #without function here jj=0
    while ii > 0 and ii <= np.floor(count / Nbtot):
        if np.remainder(ii,Ni / (10*Nbtot)) == 0:
            jj=jj + 10
            print(str(jj)+'%')
        ...
        ii=ii+1

   #in the shell
    global jj
    SyntaxError: name 'jj' is used prior to global declaration

Tags: 文件代码frompyimport程序maintkinter
1条回答
网友
1楼 · 发布于 2024-04-29 20:52:06

摩押

你已经试过这种东西了吗?你知道吗

jj = 0
self.progessBar = ttk.Progressbar(self.frame, orient="horizontal", 
                                  length=286, mode="determinate", 
                                  value=jj).pack(pady=10)

def run_progessbar(self):

    global jj
    while ii > 0 and ii <= np.floor(count / Nbtot):
    ...
        jj=jj + 10
        print(str(jj)+'%')
    ...
        ii=ii + 1

我发现了两个有用的链接:

Tkinter progress bar updating

Progress bar updating

相关问题 更多 >