Get State of a Tkinter Checkbutton

Dev Prakash Sharma
Updated on 15-Apr-2021 13:43:25

3K+ 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

Create Child Windows with Python Tkinter

Dev Prakash Sharma
Updated on 15-Apr-2021 13:41:35

7K+ 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

Create a Date Picker in Tkinter

Dev Prakash Sharma
Updated on 15-Apr-2021 13:39:25

9K+ 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

Pass Arguments to Tkinter Button's Callback Command

Dev Prakash Sharma
Updated on 15-Apr-2021 13:37:33

2K+ 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

Build Binary Tree from Inorder or Postorder Traversal in Python

AmitDiwan
Updated on 15-Apr-2021 13:35:40

416 Views

When it is required to build a binary tree by taking input using inorder or postorder traversal, a class is defined, that has methods to set the root element, perform inorder traversal, perform post order traversal. It can be used by creating an instance of the class.Below is a demonstration of the same −Example Live Democlass BinaryTree_struct:    def __init__(self, key=None):       self.key = key       self.left = None       self.right = None    def set_root(self, key):       self.key = key    def inorder_traversal(self):       if self.left is not ... Read More

Display Image Using Pillow in Tkinter

Dev Prakash Sharma
Updated on 15-Apr-2021 13:35:40

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

Find Nth Node in Inorder Traversal of a Tree in Python

AmitDiwan
Updated on 15-Apr-2021 13:35:21

238 Views

When it is required to find the ‘n’th node using inorder traversal of a binary tree, a binary tree class is created with methods to set the root element, add elements to left or right, perform in order traversal and so on. An instance of the class is created, and it can be used to access the methods.Below is a demonstration of the same −Example Live Democlass BinaryTree_struct:    def __init__(self, key=None):       self.key = key       self.left = None       self.right = None    def set_root(self, key):       self.key = key ... Read More

Convert Singly Linked List to Circular List in Python

AmitDiwan
Updated on 15-Apr-2021 13:34:59

368 Views

When it is required to convert a singly linked list into a circular linked list, a method named ‘convert_to_circular_list’ is defined that ensures that the last elements points to the first element, thereby making it circular in nature.Below is a demonstration of the same −Example Live Democlass Node:    def __init__(self, data):       self.data = data       self.next = None class LinkedList_struct:    def __init__(self):       self.head = None       self.last_node = None    def add_elements(self, data):       if self.last_node is None:          self.head = Node(data) ... Read More

Disable Typing in a TTK Combobox in Tkinter

Dev Prakash Sharma
Updated on 15-Apr-2021 13:33:03

3K+ Views

The ttk.Combobox is used to create dropdown menus in the Entry Widgets. To create the options, we just simply pass the strings to the values object of combobox. We can disable the combobox by passing the state as “readonly”.ExampleIn the following example, we will create a combobox whose state is disabled.#Import tkinter library from tkinter import * from tkinter import ttk #Create an instance of tkinter frame win = Tk() #Set the geometry of tkinter window win.geometry("750x250") #Create an instance of StringVar var= StringVar() #Create an Label Label(win, text="Select any Language", font= ('Helvetica 15 bold')).pack(pady=20) #Create Object of Tkinter Combobox ... Read More

Expand Text Widget to Fill Entire Parent Frame in Tkinter

Dev Prakash Sharma
Updated on 15-Apr-2021 13:31:30

3K+ Views

Tkinter text widgets are generally used to create text fields that support multi-line user Input. Let us suppose that we have to resize the text widget that is defined in a separate frame. To enable the text widget to resize in its full screen, we can use the columnand row configuration property of the grid system.We will use the grid_columnconfigure() property. It has four valid options like, Minsize − To provide the minimum size to the screen permitted in the application.Weight − Adds space to the widget in the layout.uniform − Place the column in a uniform group with other ... Read More

Advertisements