Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

tkinter open new window

# Source https://www.geeksforgeeks.org/open-a-new-window-with-a-button-in-python-tkinter/
# 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 :: replace transparent pixels python 
Python :: python divide floor 
Python :: python reverse array 
Python :: localize timezone python 
Python :: python add list to dictionary in loop 
Python :: prevent list index out of range python 
Python :: Python Tkinter timer animation 
Python :: discord.py get user input 
Python :: get first x characters of string python 
Python :: dataframe summary pandas 
Python :: django drop database postgres 
Python :: distinct rows in this DataFrame 
Python :: how to convert types of variablesin python 
Python :: python3 change file permissions 
Python :: force garbage collection in python 
Python :: python tkinter define window size 
Python :: root template 
Python :: python run shell command 
Python :: add custom field to serializer 
Python :: python currency 
Python :: python list of colors 
Python :: convert data type object to string python 
Python :: dataframe groupby multiple columns 
Python :: seaborn define linewidth 
Python :: print pandas version python 
Python :: load a Dictionary from File in Python Using the Load Function of the pickle Module 
Python :: packing and unpacking in python 
Python :: Python Creating string from a timestamp 
Python :: sorted vs sort python 
Python :: how to check if a list is a subset of another list 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =