Python Forum
[Tkinter] Toplevel window and global widgets?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Toplevel window and global widgets?
#1
I am using a Toplevel window for users to enter a record number (entrcrd) which is to be opened from an SQLite database.

At the initiation of the button btnopen and its command procedure I want the Toplevel window to close automatically.

The only means I have yet found to do this is to make the widgets entrcrd (Enter record ) and btnexit ( Exit) as globals and then invoke the command of the btnexit to destroy the Toplevel window filewin.

My question is this, is this approach, sloppy coding and could the objectives be achieved in a more refined manner?

Any suggestions comments or observations most welcome.

def record_open_which():
    global entrcrd
    global btnexit

    filewin=Toplevel(window)
    filewin.resizable(0, 0)
    filewin.geometry('300x100+800+40')
    filewin.title('Open a record')
    filewin.tk.call('wm', 'iconphoto', filewin._w, PhotoImage(file='resources/part.png'))

    entrcrd=Entry(filewin, relief='groove', width=12, font=('Tahoma', '7'))
    entrcrd.place(x=205, y=18)

    btnopen=Button(filewin)
    btnopen.place(x=205, y=40)
    btnopen.configure(text='Open Record', width=9, font=('Tahoma', '7'))

    btnexit=Button(filewin)
    btnexit.place(x=205, y=60)
    btnexit.configure(text='Exit', width=9, font=('Tahoma', '7'))

    btnopen.configure(command=record_to_open)
    btnexit.configure(command=filewin.destroy)


def record_to_open():
    Rcrd = entrcrd.get()
    record_open(Rcrd)
    btnexit.invoke()

Apologies Admin I've done it again, could you please move this to the general coding help folder.
Reply


Messages In This Thread
Toplevel window and global widgets? - by KevinBrown - Apr-24-2019, 02:15 PM
RE: Toplevel window and global widgets? - by Yoriz - Apr-24-2019, 05:31 PM
RE: Toplevel window and global widgets? - by Yoriz - Apr-25-2019, 06:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 607 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  pass a variable between tkinter and toplevel windows janeik 10 2,463 Jan-24-2024, 06:44 AM
Last Post: Liliana
  [Tkinter] Open tkinter colorchooser at toplevel (so I can select/focus on either window) tabreturn 4 1,974 Jul-06-2022, 01:03 PM
Last Post: deanhystad
  [Tkinter] Toplevel window menator01 5 3,119 Apr-18-2022, 06:01 PM
Last Post: menator01
  [Tkinter] Not able to get image as background in a Toplevel window finndude 4 3,965 Jan-07-2022, 10:10 PM
Last Post: finndude
  [Tkinter] Images in Toplevel() finndude 4 4,363 Mar-09-2021, 09:39 AM
Last Post: finndude
  Create image on a Toplevel using tkinter ViktorWong 3 7,897 Jun-13-2020, 03:21 PM
Last Post: deanhystad
  [Tkinter] Connect Toplevel Radiobuttons to root Label/Entry widgets iconit 2 2,499 Apr-28-2020, 06:50 AM
Last Post: iconit
  Using Tkinter widgets on child window chewy1418 8 7,324 Feb-27-2020, 10:34 PM
Last Post: Marbelous
  Transfer Toplevel window entry to root window entry with TKinter HBH 0 4,499 Jan-23-2020, 09:00 PM
Last Post: HBH

Forum Jump:

User Panel Messages

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