How to link a Progressbar between a python program and a tkinter window?
I have two .py files in a folder (Main_program.py and HMI.py). The first is a code that contains a large loop (which increments) with a print at the beginning, which displays the evolution of the code execution(10%,20%etc). And the second file is an interface, which contains a button that executes Main_program.py . I would like to create a Progressbar in my interface that would be linked to the evolution of the print in the first code. But how do we do that? thank you very much.
HMI.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
...
Main_program.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
python progress-bar ttk
add a comment |
I have two .py files in a folder (Main_program.py and HMI.py). The first is a code that contains a large loop (which increments) with a print at the beginning, which displays the evolution of the code execution(10%,20%etc). And the second file is an interface, which contains a button that executes Main_program.py . I would like to create a Progressbar in my interface that would be linked to the evolution of the print in the first code. But how do we do that? thank you very much.
HMI.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
...
Main_program.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
python progress-bar ttk
Possible duplicate of Tkinter: Updating progressbar when a function is called
– stovfl
Nov 25 '18 at 18:41
Did you import in the file Main_programm.py also the file HMI.py? I mean importing it within the your function in order to avoid circular dependency. Or place "jj = 0" as a variable in your function so it does not need to be a global variable.
– Alex_P
Nov 26 '18 at 8:23
if I do that : import HMI in Main_program, a second root window opens immediately without activating the progressbar.
– F.Moab
Nov 27 '18 at 3:54
add a comment |
I have two .py files in a folder (Main_program.py and HMI.py). The first is a code that contains a large loop (which increments) with a print at the beginning, which displays the evolution of the code execution(10%,20%etc). And the second file is an interface, which contains a button that executes Main_program.py . I would like to create a Progressbar in my interface that would be linked to the evolution of the print in the first code. But how do we do that? thank you very much.
HMI.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
...
Main_program.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
python progress-bar ttk
I have two .py files in a folder (Main_program.py and HMI.py). The first is a code that contains a large loop (which increments) with a print at the beginning, which displays the evolution of the code execution(10%,20%etc). And the second file is an interface, which contains a button that executes Main_program.py . I would like to create a Progressbar in my interface that would be linked to the evolution of the print in the first code. But how do we do that? thank you very much.
HMI.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
...
Main_program.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
python progress-bar ttk
python progress-bar ttk
edited Nov 26 '18 at 9:01
Alex_P
3341415
3341415
asked Nov 25 '18 at 17:35
F.MoabF.Moab
155
155
Possible duplicate of Tkinter: Updating progressbar when a function is called
– stovfl
Nov 25 '18 at 18:41
Did you import in the file Main_programm.py also the file HMI.py? I mean importing it within the your function in order to avoid circular dependency. Or place "jj = 0" as a variable in your function so it does not need to be a global variable.
– Alex_P
Nov 26 '18 at 8:23
if I do that : import HMI in Main_program, a second root window opens immediately without activating the progressbar.
– F.Moab
Nov 27 '18 at 3:54
add a comment |
Possible duplicate of Tkinter: Updating progressbar when a function is called
– stovfl
Nov 25 '18 at 18:41
Did you import in the file Main_programm.py also the file HMI.py? I mean importing it within the your function in order to avoid circular dependency. Or place "jj = 0" as a variable in your function so it does not need to be a global variable.
– Alex_P
Nov 26 '18 at 8:23
if I do that : import HMI in Main_program, a second root window opens immediately without activating the progressbar.
– F.Moab
Nov 27 '18 at 3:54
Possible duplicate of Tkinter: Updating progressbar when a function is called
– stovfl
Nov 25 '18 at 18:41
Possible duplicate of Tkinter: Updating progressbar when a function is called
– stovfl
Nov 25 '18 at 18:41
Did you import in the file Main_programm.py also the file HMI.py? I mean importing it within the your function in order to avoid circular dependency. Or place "jj = 0" as a variable in your function so it does not need to be a global variable.
– Alex_P
Nov 26 '18 at 8:23
Did you import in the file Main_programm.py also the file HMI.py? I mean importing it within the your function in order to avoid circular dependency. Or place "jj = 0" as a variable in your function so it does not need to be a global variable.
– Alex_P
Nov 26 '18 at 8:23
if I do that : import HMI in Main_program, a second root window opens immediately without activating the progressbar.
– F.Moab
Nov 27 '18 at 3:54
if I do that : import HMI in Main_program, a second root window opens immediately without activating the progressbar.
– F.Moab
Nov 27 '18 at 3:54
add a comment |
1 Answer
1
active
oldest
votes
Moab,
Have you tried something like this already?
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
I found two useful links:
Tkinter progress bar updating
Progress bar updating
Hi, yes I tried. In HMI.py I put :..... from Main_program import run_progessbar root= Tk() ... jj=0 self.progessBar = ttk.Progressbar(self.root, orient="horizontal",length=286, mode="determinate",value=jj) self.progessBar.place(x=1180,y=50)
and in Main_program : I put all my code in run_progessbar(self) with global, but immediately I have:SyntaxError: name 'jj' is used prior to global declaration
. I have to import run_progressbar into HMI.py, right? sorry for formatt
– F.Moab
Nov 26 '18 at 2:26
Could you please put your code in your question with the proper format? It is quite a pain to read code in a comment.
– Alex_P
Nov 26 '18 at 7:19
I put my code in the question :D
– F.Moab
Nov 26 '18 at 8:04
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53470106%2fhow-to-link-a-progressbar-between-a-python-program-and-a-tkinter-window%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Moab,
Have you tried something like this already?
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
I found two useful links:
Tkinter progress bar updating
Progress bar updating
Hi, yes I tried. In HMI.py I put :..... from Main_program import run_progessbar root= Tk() ... jj=0 self.progessBar = ttk.Progressbar(self.root, orient="horizontal",length=286, mode="determinate",value=jj) self.progessBar.place(x=1180,y=50)
and in Main_program : I put all my code in run_progessbar(self) with global, but immediately I have:SyntaxError: name 'jj' is used prior to global declaration
. I have to import run_progressbar into HMI.py, right? sorry for formatt
– F.Moab
Nov 26 '18 at 2:26
Could you please put your code in your question with the proper format? It is quite a pain to read code in a comment.
– Alex_P
Nov 26 '18 at 7:19
I put my code in the question :D
– F.Moab
Nov 26 '18 at 8:04
add a comment |
Moab,
Have you tried something like this already?
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
I found two useful links:
Tkinter progress bar updating
Progress bar updating
Hi, yes I tried. In HMI.py I put :..... from Main_program import run_progessbar root= Tk() ... jj=0 self.progessBar = ttk.Progressbar(self.root, orient="horizontal",length=286, mode="determinate",value=jj) self.progessBar.place(x=1180,y=50)
and in Main_program : I put all my code in run_progessbar(self) with global, but immediately I have:SyntaxError: name 'jj' is used prior to global declaration
. I have to import run_progressbar into HMI.py, right? sorry for formatt
– F.Moab
Nov 26 '18 at 2:26
Could you please put your code in your question with the proper format? It is quite a pain to read code in a comment.
– Alex_P
Nov 26 '18 at 7:19
I put my code in the question :D
– F.Moab
Nov 26 '18 at 8:04
add a comment |
Moab,
Have you tried something like this already?
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
I found two useful links:
Tkinter progress bar updating
Progress bar updating
Moab,
Have you tried something like this already?
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
I found two useful links:
Tkinter progress bar updating
Progress bar updating
answered Nov 25 '18 at 22:52
Alex_PAlex_P
3341415
3341415
Hi, yes I tried. In HMI.py I put :..... from Main_program import run_progessbar root= Tk() ... jj=0 self.progessBar = ttk.Progressbar(self.root, orient="horizontal",length=286, mode="determinate",value=jj) self.progessBar.place(x=1180,y=50)
and in Main_program : I put all my code in run_progessbar(self) with global, but immediately I have:SyntaxError: name 'jj' is used prior to global declaration
. I have to import run_progressbar into HMI.py, right? sorry for formatt
– F.Moab
Nov 26 '18 at 2:26
Could you please put your code in your question with the proper format? It is quite a pain to read code in a comment.
– Alex_P
Nov 26 '18 at 7:19
I put my code in the question :D
– F.Moab
Nov 26 '18 at 8:04
add a comment |
Hi, yes I tried. In HMI.py I put :..... from Main_program import run_progessbar root= Tk() ... jj=0 self.progessBar = ttk.Progressbar(self.root, orient="horizontal",length=286, mode="determinate",value=jj) self.progessBar.place(x=1180,y=50)
and in Main_program : I put all my code in run_progessbar(self) with global, but immediately I have:SyntaxError: name 'jj' is used prior to global declaration
. I have to import run_progressbar into HMI.py, right? sorry for formatt
– F.Moab
Nov 26 '18 at 2:26
Could you please put your code in your question with the proper format? It is quite a pain to read code in a comment.
– Alex_P
Nov 26 '18 at 7:19
I put my code in the question :D
– F.Moab
Nov 26 '18 at 8:04
Hi, yes I tried. In HMI.py I put :
..... from Main_program import run_progessbar root= Tk() ... jj=0 self.progessBar = ttk.Progressbar(self.root, orient="horizontal",length=286, mode="determinate",value=jj) self.progessBar.place(x=1180,y=50)
and in Main_program : I put all my code in run_progessbar(self) with global, but immediately I have: SyntaxError: name 'jj' is used prior to global declaration
. I have to import run_progressbar into HMI.py, right? sorry for formatt– F.Moab
Nov 26 '18 at 2:26
Hi, yes I tried. In HMI.py I put :
..... from Main_program import run_progessbar root= Tk() ... jj=0 self.progessBar = ttk.Progressbar(self.root, orient="horizontal",length=286, mode="determinate",value=jj) self.progessBar.place(x=1180,y=50)
and in Main_program : I put all my code in run_progessbar(self) with global, but immediately I have: SyntaxError: name 'jj' is used prior to global declaration
. I have to import run_progressbar into HMI.py, right? sorry for formatt– F.Moab
Nov 26 '18 at 2:26
Could you please put your code in your question with the proper format? It is quite a pain to read code in a comment.
– Alex_P
Nov 26 '18 at 7:19
Could you please put your code in your question with the proper format? It is quite a pain to read code in a comment.
– Alex_P
Nov 26 '18 at 7:19
I put my code in the question :D
– F.Moab
Nov 26 '18 at 8:04
I put my code in the question :D
– F.Moab
Nov 26 '18 at 8:04
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53470106%2fhow-to-link-a-progressbar-between-a-python-program-and-a-tkinter-window%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of Tkinter: Updating progressbar when a function is called
– stovfl
Nov 25 '18 at 18:41
Did you import in the file Main_programm.py also the file HMI.py? I mean importing it within the your function in order to avoid circular dependency. Or place "jj = 0" as a variable in your function so it does not need to be a global variable.
– Alex_P
Nov 26 '18 at 8:23
if I do that : import HMI in Main_program, a second root window opens immediately without activating the progressbar.
– F.Moab
Nov 27 '18 at 3:54