Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter refresh
#1
def selmunicipio():
    top = tk.Toplevel()
    top.title("Selección de Municipio")
    y=1
    for i in listamunicipios:
        y+=1
        if y<=30:
            tk.Radiobutton(top,text=i,variable=municipio,value=i).grid(row=y, column=0, sticky='w')
        else:
            tk.Radiobutton(top,text=i,variable=municipio,value=i).grid(row=y-29, column=1, sticky='w')
    button = tk.Button(top, text="Elige y pulsa aquí", command=top.destroy)
    button.grid(row=1, column=0)
tk.Entry(raiz, textvariable=municipio, validate='focus', validatecommand=selmunicipio).grid(row=11, column=1, sticky='w,e', padx=5, pady=5)
When I focus on the Entry, a window is displayed, I choose an option, I press a button and it appears in the Entry.
But once the operation is done, when I return to focus, the window does no appears again.
How can I restart the Entry?

Thanks.
Reply
#2
Your Toplevel windows scope is only in selmunicipio
once you exit this function, the window is no longer in scope and will be garbage collected
to avoid this, define top outside of function, or use a class, with top defined in the __init__
Reply
#3
At y=40, the radiobutton will overlay the Entry. Try putting the Entry in column 3 and see what happens. Note you are using municipio for both the radiobuttons and the Entry. No telling what happens. Sorry, but I don't have any idea what you are trying to do.
Reply
#4
The problem is that I have to put some widget with 60 elements. Once the element has been selected, the screen must appear.
The Optionmenu goes away from the screen and I have not managed to limit the number of elements shown and put a scrollbar.
What alternatives do I have?
Reply
#5
What do yo use the Entry for?
import sys
if 3 == sys.version_info[0]: ## 3.X is default if dual system
    import tkinter as tk     ## Python 3.x
else:
    import Tkinter as tk     ## Python 2.x

def show_choice():
    print(v.get())
    ent.delete(0, "end")

def selmunicipio():
    top = tk.Toplevel()
    top.title("Selección de Municipio")
    v.set(1)

##    for i in listamunicipios:
    for ctr in range(30):
        tk.Radiobutton(top,text=ctr+1,variable=v, command=show_choice,
                       value=ctr+1).grid(row=ctr+1, column=0, sticky='w')
        tk.Radiobutton(top,text=ctr+31,variable=v, command=show_choice,
                       value=ctr+31).grid(row=ctr+1, column=1, sticky='w')
    button = tk.Button(top, text="Elige y pulsa aquí", command=top.destroy)
    button.grid(row=100, column=0)

root=tk.Tk()
v=tk.IntVar()
ent=tk.Entry(root, bg="lightblue")
ent.grid(row=1)
tk.Button(root, text="Quit", command=root.quit).grid(row=100)
selmunicipio()
root.mainloop()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter - update/refresh treeview snakes 5 20,867 Dec-02-2023, 07:05 PM
Last Post: aynous19
  [PyQt] Refresh x-labels in matplotlib animation widget JohnT 5 3,736 Apr-23-2021, 07:40 PM
Last Post: JohnT
  Refresh image in label after every 1s using simple function jenkins43 1 5,489 Jul-28-2019, 02:49 PM
Last Post: Larz60+
  Unable to update or refresh label text in tkinter jenkins43 3 6,592 Jul-24-2019, 02:09 PM
Last Post: Friend
  [Tkinter] Label doesn't refresh jollydragon 7 6,961 Jul-13-2018, 05:55 AM
Last Post: jollydragon
  [PyQt] enviremont refresh duende 2 3,421 May-13-2018, 09:49 AM
Last Post: duende
  pyqt main window refresh poblems duende 0 5,367 Apr-13-2018, 05:05 PM
Last Post: duende
  Refresh test in urwid.Text Stensborg 1 4,530 Mar-05-2018, 11:23 AM
Last Post: Stensborg
  [Tkinter] problem with refresh UI in tkinter app Philbot 5 10,816 Feb-06-2018, 01:10 PM
Last Post: Philbot
  How Can I Do Refresh Window? satrancali 0 7,073 Feb-03-2018, 07:50 AM
Last Post: satrancali

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020