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










0















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?










share|improve this question

















  • 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















0















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?










share|improve this question

















  • 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













0












0








0








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?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 an if statement that first checks to see if the frame is hidden.

    – Mike - SMT
    Mar 6 at 15:28












  • 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







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












1 Answer
1






active

oldest

votes


















0














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()





share|improve this answer























  • 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










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
);



);













draft saved

draft discarded


















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









0














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()





share|improve this answer























  • 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















0














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()





share|improve this answer























  • 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













0












0








0







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()





share|improve this answer













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()






share|improve this answer












share|improve this answer



share|improve this answer










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

















  • 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



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved