Apr-24-2019, 02:15 PM
(This post was last modified: Apr-24-2019, 02:32 PM by KevinBrown.)
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.
Apologies Admin I've done it again, could you please move this to the general coding help folder.
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
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.