Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to make a button open a new window in python

# This will import all the widgets
# and modules which are available in
# tkinter and ttk module
from tkinter import *
from tkinter.ttk import *
 
# creates a Tk() object
master = Tk()
 
# sets the geometry of main
# root window
master.geometry("200x200")
 
 
# function to open a new window
# on a button click
def openNewWindow():
     
    # Toplevel object which will
    # be treated as a new window
    newWindow = Toplevel(master)
 
    # sets the title of the
    # Toplevel widget
    newWindow.title("New Window")
 
    # sets the geometry of toplevel
    newWindow.geometry("200x200")
 
    # A Label widget to show in toplevel
    Label(newWindow,
          text ="This is a new window").pack()
 
 
label = Label(master,
              text ="This is the main window")
 
label.pack(pady = 10)
 
# a button widget which will open a
# new window on button click
btn = Button(master,
             text ="Click to open a new window",
             command = openNewWindow)
btn.pack(pady = 10)
 
# mainloop, runs infinitely
mainloop()
Comment

PREVIOUS NEXT
Code Example
Python :: python how to get data from dictionary 
Python :: python check if object is empty 
Python :: find index of sublist in list python 
Python :: get mean using python 
Python :: odoo sorted 
Python :: append string python 
Python :: python not in 
Python :: beautifulsoup 
Python :: best scraping package in python 
Python :: Update All Python Packages On Windows 
Python :: python remove file with pattern 
Python :: how to count number of records in json 
Python :: data must be 1-dimensional pd.dataframe 
Python :: random pick between given things python 
Python :: convert float to string python 
Python :: matplotlib 
Python :: ajouter element liste python 
Python :: read a csv file in pandas 
Python :: boxplot python 
Python :: add icon to exe file 
Python :: pandas transform 
Python :: keras loss plot 
Python :: WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. 
Python :: strptime python 
Python :: stack in python using linked list 
Python :: seaborn modificar o tamanho dos graficos 
Python :: multiple input to list 
Python :: check word in list 
Python :: if and else in python 
Python :: python fiboncci 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =