Helpful Information
 
 
Category: Python
Python GUI

Can any body help me with Python..

The problem is I am making a sample GUI script I included a button which opens a new window the problem is when I click the exit button on new window it closes both windows the code is


from Tkinter import *
from tkMessageBox import showinfo

def reply( ):
showinfo(title='Pressed!', message='Button is pressed')

def button1( ):
showinfo(title='Button1', message='Button1 pressed!')

def button2( ):
showinfo(title='Button2', message='Button2 pressed!')

def button3( ):
showinfo(title='Button3', message='Button3 pressed!')

def new():
new = Toplevel()
new.iconbitmap('favicon.ico')
Label(new, text='new window').pack()
Button(new, text='close', command=new.quit).pack(side=BOTTOM)


def showname(name):
if name == '':
showinfo(title='your name', message='Please enter your name')
else:
showinfo(title='your name', message='Hi %s!' % name)


window = Tk( )
window.title('Sample')
window.iconbitmap('favicon.ico')

button = Button(window, text='press', command=reply)
button.pack( )

btn1 = Button(window, text='Button1', command=button1)
btn1.pack()

btn2 = Button(window, text='Button2', command=button2)
btn2.pack()

btn3 = Button(window, text='Button3', command=button3)
btn3.pack()

btn5 = Button(window, text='New Window', command=new)
btn5.pack()

Label(window, text="Enter your name:").pack()
ent = Entry(window)
ent.pack()

btn4 = Button(window, text='Submit', command=(lambda: showname(ent.get( ))))
btn4.pack(side=BOTTOM)

window.mainloop( )



Thanx in advance










privacy (GDPR)