- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What's the difference between Tkinter's Tk and Toplevel classes?
Tkinter windows are created by initializing the Tk object first. It is the minimal part of any Tkinter application, which helps to instantiate the application. Tk helps to construct the basic building blocks of the application, such as an application window where all the widgets are placed.
However, Toplevel classes help to communicate through the internal widgets of the main application. One of the examples of toplevel classes is the Toplevel window that displays a child window other than the main window of the application. The Toplevel window works the same as the Tk, as it also can contain widgets and functionalities.
Example
#Import the required libraries from tkinter import * #Create an instance of Tkinter Frame win = Tk() #Set the geometry win.geometry("700x350") #Set the default color of the window win.config(bg= '#acc7df') def open_win(): #Create a Button to Open the Toplevel Window top= Toplevel(win) top.geometry("700x250") top.title("Child Window") #Create a label in Toplevel window Label(top, text= "Hello World!") Button(win, text= "Click Me", background= "white", foreground= "red3", font= ('Helvetica 13 bold'), command= open_win).pack(pady= 50) win.mainloop()
Output
Running the above code will display a window that contains a button.
Now, click the "Click Me" Button to open a child window.
- Related Articles
- What's the difference between "update" and "update_idletasks" in Tkinter?
- What's the difference between sizeof and alignof?
- What's the difference between window.location and document.location?
- What's the Difference between Skills and Competencies?
- What's the difference between Matplotlib.pyplot and Matplotlib.figure?
- What's the difference between "!!" and "?" in Kotlin?
- What's the difference between "STL" and "C++ Standard Library"?
- What is the difference between Python's re.search and re.match?
- What's the difference between lists and tuples in Python?
- What's the difference between RSpec and Cucumber in Selenium?
- What's the difference between nohup and ampersand (&) on Linux?
- How to delete all children's elements using Python's Tkinter?
- C/C++ difference's between strncmp() and strcmp.
- What's the Kotlin equivalent of Java's String[]?
- What's the difference between assignment operator and copy constructor in C++?
