[Tkinter-discuss] How to eliminate flickers when swapping frames?
Nam Nguyen
namnguyen at google.com
Wed Mar 28 16:07:54 EDT 2018
This happens in Tcl/Tk too. I'll follow up with the Tk folks and come back
if there's any fix or workaround.
#!/usr/bin/env tclsh
package require Tk
bind . {<Escape>} {destroy .}
wm minsize . 1280 800
frame .f_1
button .f_1.b -text {Frame 1} -command {destroy .}
pack .f_1.b -expand true -fill both
frame .f_2
button .f_2.b -text {2 emarF} -command {destroy .}
pack .f_2.b -expand true -fill both
set current 1
set delay 500
proc flip {} {
global current
global delay
pack forget ".f_$current"
if {$current == 1} then {
set current 2
} else {
set current 1
}
pack ".f_$current" -expand true -fill both
after $delay {flip}
}
pack ".f_$current" -expand true -fill both
after $delay {flip}
On Wed, Mar 28, 2018 at 2:42 AM, Michael Lange <klappnase at web.de> wrote:
> Hi,
>
> On Wed, 28 Mar 2018 01:18:50 +0000
> Nam Nguyen <namnguyen at google.com> wrote:
>
> > Is my code out of whack or is it "standard" enough to your seasoned
> > eyes? Is there any guess as to a fix to this flickering, be it with my
> > code, or Tk itself?
>
> of course you could address the "mouse over widget" issue with something
> like
>
> b1 = tk.Button(f_1, text='Frame 1', font=my_font)
> b1.pack(expand=True, fill=tk.BOTH)
> bg = b1.cget('background')
> b1.configure(activebackground=bg)
> f_2 = tk.Frame(root)
> tk.Button(f_2, text='Frame 2'[::-1], font=my_font,
> activebackground=bg).pack( expand=True, fill=tk.BOTH)
>
> For the flicker that remains, I don't think there is much one can do
> about it. If my assumption that it comes simply from the redrawing
> operation is correct, I am afraid that there is no remedy (at least none
> that I am aware of). Here it is barely visible but this might depend on
> the speed of the system. When Brian says that he does not notice any
> flicker at all, that might just be because his machine is faster than
> mine. Of course there is still a chance that I have been missing
> something.
>
> Best regards
>
> Michael
>
>
> .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-.
>
> Our way is peace.
> -- Septimus, the Son Worshiper, "Bread and Circuses",
> stardate 4040.7.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20180328/adc29127/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4849 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20180328/adc29127/attachment.bin>
More information about the Tkinter-discuss
mailing list