How to call a new window on button click.



Here we will learn how to assign an action to button. 
To assign action, command option needs to be used. A value (method / function) assigned to command will be triggered on button click.

below is the code to destroy the main window on click, GUI will look like as above image


 command = action to perform


to destroy current window,  function_call  needs to assign to command option to open a new window for confirmation to close
(please refer project1 and project2 before going forward) 


#project to destroy window

try:
from Tkinter import *
except:
from tkinter import *

def destroy_win(mw1):
mw1.destroy()
mw.destroy()


def close_window():
mw1 = Tk()
mw1.geometry(
"170x50+365+80")
mw1.title(
"AETies")

lbl = Label(mw1
, text="confirm to close")
lbl.pack(
side=LEFT)

btn = Button(mw1
, text='confirm', command= lambda:destroy_win(mw1))
btn.pack(
side=LEFT)

mw1.mainloop()

mw = Tk()
mw.geometry(
"500x100+50+50")
mw.title(
"AETies : Automation Expert Technologies")

label = Label(mw
, text='Please click on button to close window')
label.pack(
side=LEFT)
btn = Button(mw
, text='click here', command=close_window)
btn.pack(
side=LEFT)

mw.mainloop()







Comments

My photo
Techno Xpresss
Bangalore, Karnataka, India