tkinter only refresh visible frame using after2019 Community Moderator ElectionBest way to structure a tkinter applicationpython - Tkinter not responding when simultaneously updating multiple labelsTkinter frame blankscrollbar for labels frame in tkinterDisplaying Pandas dataframe in tkinterPython 3 Tkinter - How to use the same widgets in several frames, writing the widgets only once and calling them when requiredDynamic frame content python3 tkinterTkinter how to reset window/frame in multi-framed application?Updating/Refreshing python Tkinter FramesCombining scrollbar technik with tkinter way to change frames
A Tag-Friendly Word or Phrase Expressing Failure to Communicate Meaning Due to Word Choice
In the late 1940’s to early 1950’s what technology was available that could melt a LOT of ice?
Reversed Sudoku
If I receive an SOS signal, what is the proper response?
Vocabulary for giving just numbers, not a full answer
How did Alan Turing break the enigma code using the hint given by the lady in the bar?
Error during using callback start_page_number in lualatex
How are showroom/display vehicles prepared?
Can one live in the U.S. and not use a credit card?
How many characters using PHB rules does it take to be able to have access to any PHB spell at the start of an adventuring day?
Could you please stop shuffling the deck and play already?
Latex does not go to next line
Hotkey (or other quick way) to insert a keyframe for only one component of a vector-valued property?
Accountant/ lawyer will not return my call
Do items de-spawn in Diablo?
Is "history" a male-biased word ("his+story")?
Plausibility of Mushroom Buildings
List elements digit difference sort
Why does liquid water form when we exhale on a mirror?
What wound would be of little consequence to a biped but terrible for a quadruped?
Word for a person who has no opinion about whether god exists
NASA's RS-25 Engines shut down time
How do I express some one as a black person?
How strictly should I take "Candidates must be local"?
tkinter only refresh visible frame using after
2019 Community Moderator ElectionBest way to structure a tkinter applicationpython - Tkinter not responding when simultaneously updating multiple labelsTkinter frame blankscrollbar for labels frame in tkinterDisplaying Pandas dataframe in tkinterPython 3 Tkinter - How to use the same widgets in several frames, writing the widgets only once and calling them when requiredDynamic frame content python3 tkinterTkinter how to reset window/frame in multi-framed application?Updating/Refreshing python Tkinter FramesCombining scrollbar technik with tkinter way to change frames
I am writing a GUI that takes and displays live data from multiple sensors. I have different frames in my GUI between which you can navigate. At this moment every frame is refreshing at 25Hz using an 'after' method call.
I think (but I'm not sure) that the frames are also refreshing even when hidden for the user (when the user is seeing another frame). This of course eats resources, so I was wondering how to only refresh a frame when you are looking at it?
python-3.x tkinter
add a comment |
I am writing a GUI that takes and displays live data from multiple sensors. I have different frames in my GUI between which you can navigate. At this moment every frame is refreshing at 25Hz using an 'after' method call.
I think (but I'm not sure) that the frames are also refreshing even when hidden for the user (when the user is seeing another frame). This of course eats resources, so I was wondering how to only refresh a frame when you are looking at it?
python-3.x tkinter
1
Use a tracking variable. When frame is hidden make sure this variable is updated and in your method that runs the after statement you add anif
statement that first checks to see if the frame is hidden.
– Mike - SMT
Mar 6 at 15:28
add a comment |
I am writing a GUI that takes and displays live data from multiple sensors. I have different frames in my GUI between which you can navigate. At this moment every frame is refreshing at 25Hz using an 'after' method call.
I think (but I'm not sure) that the frames are also refreshing even when hidden for the user (when the user is seeing another frame). This of course eats resources, so I was wondering how to only refresh a frame when you are looking at it?
python-3.x tkinter
I am writing a GUI that takes and displays live data from multiple sensors. I have different frames in my GUI between which you can navigate. At this moment every frame is refreshing at 25Hz using an 'after' method call.
I think (but I'm not sure) that the frames are also refreshing even when hidden for the user (when the user is seeing another frame). This of course eats resources, so I was wondering how to only refresh a frame when you are looking at it?
python-3.x tkinter
python-3.x tkinter
asked Mar 6 at 15:26
ThaNoobThaNoob
669
669
1
Use a tracking variable. When frame is hidden make sure this variable is updated and in your method that runs the after statement you add anif
statement that first checks to see if the frame is hidden.
– Mike - SMT
Mar 6 at 15:28
add a comment |
1
Use a tracking variable. When frame is hidden make sure this variable is updated and in your method that runs the after statement you add anif
statement that first checks to see if the frame is hidden.
– Mike - SMT
Mar 6 at 15:28
1
1
Use a tracking variable. When frame is hidden make sure this variable is updated and in your method that runs the after statement you add an
if
statement that first checks to see if the frame is hidden.– Mike - SMT
Mar 6 at 15:28
Use a tracking variable. When frame is hidden make sure this variable is updated and in your method that runs the after statement you add an
if
statement that first checks to see if the frame is hidden.– Mike - SMT
Mar 6 at 15:28
add a comment |
1 Answer
1
active
oldest
votes
Here is a simple example that shows how one could track what frame is currently the top frame and only update that frames data.
This is not the only way and probably not even the best way but its should serve to give you an starting point.
import tkinter as tk
root = tk.Tk()
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
timer1 = 0
timer2 = 0
frame1 = tk.Frame(root)
frame2 = tk.Frame(root)
frame2.grid(row=0, column=0, sticky='nsew')
frame1.grid(row=0, column=0, sticky='nsew')
frame1.tkraise()
current_active_frame = frame1
lbl1 = tk.Label(frame1, text='Active Counter at: 0')
lbl2 = tk.Label(frame2, text='Active Counter at: 0')
lbl1.grid(row=0, column=0, sticky='nsew')
lbl2.grid(row=0, column=0, sticky='nsew')
tk.Button(frame1, text='Switch to frame 2', command=lambda: raise_frame(frame2)).grid(row=1, column=0, sticky='nsew')
tk.Button(frame2, text='Switch to frame 1', command=lambda: raise_frame(frame1)).grid(row=1, column=0, sticky='nsew')
def raise_frame(frame):
global current_active_frame
frame.tkraise()
current_active_frame = frame
def update_while_active():
global timer1, timer2
if current_active_frame == frame1:
print('frame1')
timer1 += 1
lbl1.config(text='Active Counter at: '.format(timer1))
if current_active_frame == frame2:
print('frame2')
timer2 += 1
lbl2.config(text='Active Counter at: '.format(timer2))
root.after(1000, update_while_active)
update_while_active()
root.mainloop()
Thanks! So simple, weird that I couldn't find this online. I did not test it yet in my code, but the example works so it should work with my code as well.
– ThaNoob
Mar 8 at 9:14
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%2f55026612%2ftkinter-only-refresh-visible-frame-using-after%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
Here is a simple example that shows how one could track what frame is currently the top frame and only update that frames data.
This is not the only way and probably not even the best way but its should serve to give you an starting point.
import tkinter as tk
root = tk.Tk()
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
timer1 = 0
timer2 = 0
frame1 = tk.Frame(root)
frame2 = tk.Frame(root)
frame2.grid(row=0, column=0, sticky='nsew')
frame1.grid(row=0, column=0, sticky='nsew')
frame1.tkraise()
current_active_frame = frame1
lbl1 = tk.Label(frame1, text='Active Counter at: 0')
lbl2 = tk.Label(frame2, text='Active Counter at: 0')
lbl1.grid(row=0, column=0, sticky='nsew')
lbl2.grid(row=0, column=0, sticky='nsew')
tk.Button(frame1, text='Switch to frame 2', command=lambda: raise_frame(frame2)).grid(row=1, column=0, sticky='nsew')
tk.Button(frame2, text='Switch to frame 1', command=lambda: raise_frame(frame1)).grid(row=1, column=0, sticky='nsew')
def raise_frame(frame):
global current_active_frame
frame.tkraise()
current_active_frame = frame
def update_while_active():
global timer1, timer2
if current_active_frame == frame1:
print('frame1')
timer1 += 1
lbl1.config(text='Active Counter at: '.format(timer1))
if current_active_frame == frame2:
print('frame2')
timer2 += 1
lbl2.config(text='Active Counter at: '.format(timer2))
root.after(1000, update_while_active)
update_while_active()
root.mainloop()
Thanks! So simple, weird that I couldn't find this online. I did not test it yet in my code, but the example works so it should work with my code as well.
– ThaNoob
Mar 8 at 9:14
add a comment |
Here is a simple example that shows how one could track what frame is currently the top frame and only update that frames data.
This is not the only way and probably not even the best way but its should serve to give you an starting point.
import tkinter as tk
root = tk.Tk()
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
timer1 = 0
timer2 = 0
frame1 = tk.Frame(root)
frame2 = tk.Frame(root)
frame2.grid(row=0, column=0, sticky='nsew')
frame1.grid(row=0, column=0, sticky='nsew')
frame1.tkraise()
current_active_frame = frame1
lbl1 = tk.Label(frame1, text='Active Counter at: 0')
lbl2 = tk.Label(frame2, text='Active Counter at: 0')
lbl1.grid(row=0, column=0, sticky='nsew')
lbl2.grid(row=0, column=0, sticky='nsew')
tk.Button(frame1, text='Switch to frame 2', command=lambda: raise_frame(frame2)).grid(row=1, column=0, sticky='nsew')
tk.Button(frame2, text='Switch to frame 1', command=lambda: raise_frame(frame1)).grid(row=1, column=0, sticky='nsew')
def raise_frame(frame):
global current_active_frame
frame.tkraise()
current_active_frame = frame
def update_while_active():
global timer1, timer2
if current_active_frame == frame1:
print('frame1')
timer1 += 1
lbl1.config(text='Active Counter at: '.format(timer1))
if current_active_frame == frame2:
print('frame2')
timer2 += 1
lbl2.config(text='Active Counter at: '.format(timer2))
root.after(1000, update_while_active)
update_while_active()
root.mainloop()
Thanks! So simple, weird that I couldn't find this online. I did not test it yet in my code, but the example works so it should work with my code as well.
– ThaNoob
Mar 8 at 9:14
add a comment |
Here is a simple example that shows how one could track what frame is currently the top frame and only update that frames data.
This is not the only way and probably not even the best way but its should serve to give you an starting point.
import tkinter as tk
root = tk.Tk()
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
timer1 = 0
timer2 = 0
frame1 = tk.Frame(root)
frame2 = tk.Frame(root)
frame2.grid(row=0, column=0, sticky='nsew')
frame1.grid(row=0, column=0, sticky='nsew')
frame1.tkraise()
current_active_frame = frame1
lbl1 = tk.Label(frame1, text='Active Counter at: 0')
lbl2 = tk.Label(frame2, text='Active Counter at: 0')
lbl1.grid(row=0, column=0, sticky='nsew')
lbl2.grid(row=0, column=0, sticky='nsew')
tk.Button(frame1, text='Switch to frame 2', command=lambda: raise_frame(frame2)).grid(row=1, column=0, sticky='nsew')
tk.Button(frame2, text='Switch to frame 1', command=lambda: raise_frame(frame1)).grid(row=1, column=0, sticky='nsew')
def raise_frame(frame):
global current_active_frame
frame.tkraise()
current_active_frame = frame
def update_while_active():
global timer1, timer2
if current_active_frame == frame1:
print('frame1')
timer1 += 1
lbl1.config(text='Active Counter at: '.format(timer1))
if current_active_frame == frame2:
print('frame2')
timer2 += 1
lbl2.config(text='Active Counter at: '.format(timer2))
root.after(1000, update_while_active)
update_while_active()
root.mainloop()
Here is a simple example that shows how one could track what frame is currently the top frame and only update that frames data.
This is not the only way and probably not even the best way but its should serve to give you an starting point.
import tkinter as tk
root = tk.Tk()
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
timer1 = 0
timer2 = 0
frame1 = tk.Frame(root)
frame2 = tk.Frame(root)
frame2.grid(row=0, column=0, sticky='nsew')
frame1.grid(row=0, column=0, sticky='nsew')
frame1.tkraise()
current_active_frame = frame1
lbl1 = tk.Label(frame1, text='Active Counter at: 0')
lbl2 = tk.Label(frame2, text='Active Counter at: 0')
lbl1.grid(row=0, column=0, sticky='nsew')
lbl2.grid(row=0, column=0, sticky='nsew')
tk.Button(frame1, text='Switch to frame 2', command=lambda: raise_frame(frame2)).grid(row=1, column=0, sticky='nsew')
tk.Button(frame2, text='Switch to frame 1', command=lambda: raise_frame(frame1)).grid(row=1, column=0, sticky='nsew')
def raise_frame(frame):
global current_active_frame
frame.tkraise()
current_active_frame = frame
def update_while_active():
global timer1, timer2
if current_active_frame == frame1:
print('frame1')
timer1 += 1
lbl1.config(text='Active Counter at: '.format(timer1))
if current_active_frame == frame2:
print('frame2')
timer2 += 1
lbl2.config(text='Active Counter at: '.format(timer2))
root.after(1000, update_while_active)
update_while_active()
root.mainloop()
answered Mar 6 at 15:48
Mike - SMTMike - SMT
9,69121435
9,69121435
Thanks! So simple, weird that I couldn't find this online. I did not test it yet in my code, but the example works so it should work with my code as well.
– ThaNoob
Mar 8 at 9:14
add a comment |
Thanks! So simple, weird that I couldn't find this online. I did not test it yet in my code, but the example works so it should work with my code as well.
– ThaNoob
Mar 8 at 9:14
Thanks! So simple, weird that I couldn't find this online. I did not test it yet in my code, but the example works so it should work with my code as well.
– ThaNoob
Mar 8 at 9:14
Thanks! So simple, weird that I couldn't find this online. I did not test it yet in my code, but the example works so it should work with my code as well.
– ThaNoob
Mar 8 at 9:14
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%2f55026612%2ftkinter-only-refresh-visible-frame-using-after%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
1
Use a tracking variable. When frame is hidden make sure this variable is updated and in your method that runs the after statement you add an
if
statement that first checks to see if the frame is hidden.– Mike - SMT
Mar 6 at 15:28