- 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
Why do we use import * and then ttk in TKinter?
In order to work with a tkinter application, we have to install and import the tkinter library in our environment. Generally, we import the tkinter library in the environment by using from tkinter import * command.
The significance of "import *" represents all the functions and built-in modules in the tkinter library. By importing all the functions and methods, we can use the inbuilt functions or methods in a particular application without importing them implicitly.
There are lots of widgets, functions, methods available in tkinter library which can be used to construct the component of a particular application. Tkinter provides the ttk package that is used to style the widget's property and its look and feel. In order to use the ttk package, we have to import it by typing the following code −;
from tkinter import ttk
Example
In this particular example, we will create a functional application that will contain a button and a label widget.
#Import tkinter library from tkinter import * from tkinter import ttk #Create an instance of tkinter frame or window win= Tk() #Set the geometry of tkinter frame win.geometry("750x250") #Define the function to close the window def change_text(): label.configure(text="Welcome") #Create a label label=Label(win, text= "Click the below button to Change this Text", font=('Aerial 20 bold')) label.pack(pady=30) #Create a button widget button= ttk.Button(win, text="Commit",command=lambda:change_text()) button.pack() win.mainloop()
Output
Executing the above code will display a window that contains a button and a text label showing some text. When we click the button, it will change the message on the screen.
Now, click the "Commit" button to change the Label text.
- Related Articles
- Why we do not import a package while we use any string function?
- Why do we use import statement in Java? Where it should be included in the class?
- Difference between import tkinter as tk and from tkinter import
- Why do we use "use strict" in JavaScript?
- Why do we use random.seed() in Python?
- Why do we use interfaces in Java?
- Why do we use brackets in BODMAS?
- Why do we use pandas in python?
- Why do we use Convex Mirrors ?
- Why do we use comma operator in C#?
- Why do we use internal keyword in C#?
- Why do we use modifiers in C/C++?
- Why do we use restrict qualifier in C++?
- Why do we use const qualifier in C++?
- Why do we use JSON.stringify() method in jQuery?
