- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
Found 604 Articles for Tkinter
25K+ Views
Tkinter Label widget can be aligned using the anchor attributes. In order to calculate the accommodate spacing and alignment of the widget, anchor would help in a better way. Anchor provides several options such as N, W, S, E, NW, NE. SW, SE which can be defined in the pack manager itself.ExampleIn the following example, we will align the Label text of an application to the left by adding the anchor attribute towards “w” direction.#Import the required library from tkinter import* #Create an instance of tkinter frame win= Tk() #Set the geometry win.geometry("750x250") #Create a Label Widget Label(win, text= "New ... Read More
34K+ Views
Canvas is undoubtedly one of the most versatile widgets in Tkinter. With Canvas, we can create shapes, texts, animate stuff, modeling 3D shapes, modeling simulations, and many more.In order to add text inside a tkinter frame, we can use the create_text() method. We can define create_text() by adding values of font, text, and other options such as create_text(x, y, font, text, options….).Example#Import the required library from tkinter import * #Create an instance of tkinter frame win= Tk() #Set the geometry win.geometry("750x280") #Create a canvas object canvas= Canvas(win, width= 1000, height= 750, bg="SpringGreen2") #Add a text in ... Read More
8K+ Views
Let us assume that we are creating a tkinter application where two or more widgets are placed using a grid property. We have to add some space between the widgets in order to style their appearance. To provide space in the widgets, we can use padding property, as padding adds space to the outermost part of the widget. In order to add padding, assign the values to padx and pady.Example#Import the required library from tkinter import * #create an instance of tkinter frame win= Tk() win.geometry("750x250") #Create some Button widgets Label(win, text= "New Line Text", font= ('Helvetica 20 bold')).grid(row=0, column=5, ... Read More
3K+ Views
In various applications, tkinter widgets are required to be focused to make them active. Widgets can also grab focus and prevent the other events outside the bounds. To manage and give focus to a particular widget, we generally use the focus_set() method. It focuses the widget and makes them active until the termination of the program.ExampleIn the following example, we have created two widgets: an Entry widget and a text widget in the same window. By using the focus_set() method, we will activate the focus on the text widget.#Import tkinter library from tkinter import * from PIL import Image, ImageTk ... Read More
16K+ Views
Tkinter initially creates an instance of a window which is a container that contains all the widgets and the elements. If we want to resize the window, we can use the geometry method by defining the value of width and height.In order to get the width and height of the tkinter window, we can use winfo_width() and winfo_height() helper methods that help to grab the current width and height of the tkinter window.Example# Import tkinter library from tkinter import * # Create an instance of tkinter frame win = Tk() # Set the Geometry win.geometry("750x250") def print_width(): print("The width ... Read More
2K+ Views
Tkinter provides a variety of input widgets such as entry widget, text widget, listbox, combobox, spinbox, checkbox, etc. Checkboxes are used for taking validity input and the state gets active whenever the user clicks on the checkbutton. In terms of a particular application, we can check the state of the tkinter CheckButtons by using the state() method. It prints the actual state of the tkinter checkbuttons.Example#Import the required library from tkinter import* from tkinter import ttk #Create an instance of tkinter frame win= Tk() #Set the geometry win.geometry("750x250") #Define geometry of the window win.geometry("750x250") #Create CheckButtons chk= ttk.Checkbutton(win, text="Python") chk.pack() ... Read More
5K+ Views
The child window can be referred to as the independent window which is separated from the root or main window. In order to create a child window, we have to define a toplevel window which can be created manually using the Toplevel(win) method. In the method toplevel(root), we have to pass the main window as the parameter and further define the widgets if needed.ExampleLet us create a child window which contains some widgets in it.#Import tkinter library from tkinter import * from tkinter import ttk #Create an instance of tkinter frame win = Tk() #Set the geometry and title of ... Read More
7K+ Views
Tkcalendar is a Python package which provides DateEntry and Calendar widgets for tkinter applications. In this article, we will create a date picker with the help of DateEntry Widget.A DateEntry widget contains three fields that refer to the general format of Date as MM/DD/YY. By creating an object of DateEntry widget, we can choose a specific Date in the application.Example#Import tkinter library from tkinter import * from tkcalendar import Calendar, DateEntry #Create an instance of tkinter frame win= Tk() #Set the Geometry win.geometry("750x250") win.title("Date Picker") #Create a Label Label(win, text= "Choose a Date", background= 'gray61', foreground="white").pack(padx=20, pady=20) #Create a Calendar ... Read More
1K+ Views
Tkinter Buttons are used for handling certain operations in the application. In order to handle such events, we generally pass the defined function name as the value in the callback command. For a particular event, we can also pass the argument to the function in the button’s command.There are two ways to pass the argument to the tkinter button command −Using Lambda or anonymous functionUsing PartialsExampleIn this example, we will create a simple application that will contain a text label and a button to change the value of label text. We will pass the label as the argument in the ... Read More
1K+ Views
Python provides Pillow Package (PIL) to process and load the images in the application. An image can be loaded using the inbuilt Image.open("image location") method. Further, we can use a Label widget to display the Image in the window.Example#Import tkinter library from tkinter import * from PIL import Image, ImageTk #Create an instance of tkinter frame win = Tk() #Set the geometry win.geometry("750x550") #Load the image img= Image.open("tutorialspoint.jpg") #Convert To photoimage tkimage= ImageTk.PhotoImage(img) #Display the Image label=Label(win, image=tkimage) label.pack() win.mainloop()OutputRunning the above code will display an image in the window.Before executing the code, make sure you have the image in ... Read More