Make a Tkinter Window Not Resizable

Dev Prakash Sharma
Updated on 26-Mar-2021 10:39:51

10K+ Views

Tkinter initially creates a resizable window for every application. Let us suppose that we want to make a non-resizable window in an application. In this case, we can use resizable(height, width) and pass the value of height=None and width=None. The method also works by passing Boolean values as resizable(False, False).Example#Import the required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Set the geometry of frame win.geometry("600x250") #Set the resizable property False win.resizable(False, False) #Create a label for the window or frame Label(win, text="Hello World!", font=('Helvetica bold', 20), anchor="center").pack(pady=20) win.mainloop()OutputRunning the above code will ... Read More

Put Tkinter Window on Top of Others

Dev Prakash Sharma
Updated on 26-Mar-2021 10:37:05

13K+ Views

Whenever we create a GUI program, tkinter generally presents the output screen in the background. In other words, tkinter displays the program window behind other programs. In order to put the tkinter window on top of others, we are required to use attributes('- topmost', True) property. It pulls up the window on the upside.Example#Importing the library from tkinter import * #Create an instance of tkinter window or frame win= Tk() #Setting the geometry of window win.geometry("600x350") #Create a Label Label(win, text= "Hello World! ", font=('Helvetica bold', 15)).pack(pady=20) #Make the window jump above all win.attributes('-topmost', True) ... Read More

Set Default Text for a Tkinter Entry Widget

Dev Prakash Sharma
Updated on 26-Mar-2021 10:33:01

7K+ Views

Tkinter Entry widget is used to print and display a single line of text taken from the user Input. It is used for many applications such as creating login forms, signup forms, and other user interaction forms.We can set the default text for the Entry Widget using insert() function by passing the default text as the argument.ExampleIn this example, we have created an Entry widget that has a default text.#Import the tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() #Set the geometry win.geometry("650x250") #Create an Entry Widget entry= Entry(win) entry.insert(END, 'Enter ... Read More

Set Border Color of Tkinter Widgets

Dev Prakash Sharma
Updated on 26-Mar-2021 10:31:05

3K+ Views

Let us suppose we want to change the border color of a tkinter widget. We can configure the widget by passing the highlightcolor, highlightbackground property of the widget.ExampleIn this example, we have created an Entry widget and a button that can be triggered to change the border color of the Entry Widget.#Import the required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Set the geometry of frame win.geometry("600x250") #Define a function to change the color of entry widget def change_color():    text.config(highlightthickness=2, highlightbackground="red") #Create a Entry widget for which we want ... Read More

Set Text Value of Entry Widget Using a Button in Tkinter

Dev Prakash Sharma
Updated on 26-Mar-2021 10:29:12

10K+ Views

Tkinter Entry widget is used to display a single line text. Using tkinter Entry widget, we can set its value or content by triggering a button. It has mainly two types of operation: insert and delete.Using the Tkinter Button widget, we will set the content of the Entry widget.Example#Import the required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Define a function to change the value def change_text(txt):    text.delete(0, END)    text.insert(0, txt) #Set the geometry of frame win.geometry("600x250") #Create an Entry Widget text= Entry(win) text.pack() #Create a button ... Read More

Modify Default Font in Python Tkinter

Dev Prakash Sharma
Updated on 26-Mar-2021 10:24:31

4K+ Views

In order to change the default behavior of tkinter widgets, we generally override the option_add() method. The properties and values passed to option_add() method will reflect the changes in all the widgets in the application. Thus, changing the default font will affect the font for all the widgets defined in the application.ExampleHere we will pass two parameters into the option_add() method, i.e., option_add("*font", "font-family font-size font-style font-orientation").#Import the required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Set the geometry of frame win.geometry("600x400") #Change the default Font that will affect in all ... Read More

Setting Background Color for Tkinter in Python

Dev Prakash Sharma
Updated on 26-Mar-2021 10:20:36

3K+ Views

We can customize the tkinter widgets using the tkinter.ttk module. Tkinter.ttk module is used for styling the tkinter widgets such as setting the background color, foreground color, activating the buttons, adding images to labels, justifying the height and width of widgets, etc.In order to add a background color in tkinter widgets, we can specify the background property in the widget.ExampleIn the following example, we will create a button that will change the background of the text label.#Import the tkinter library from tkinter import * from tkinter.ttk import * #Create an instance of tkinter frame win = Tk() #Set the ... Read More

Difference Between root.destroy() and root.quit() in Tkinter Python

Dev Prakash Sharma
Updated on 26-Mar-2021 10:19:20

6K+ Views

When we invoke the destroy() method with the tkinter window object, it terminates the mainloop process and destroys all the widgets inside the window. Tkinter destroy() method is mainly used to kill and terminate the interpreter running in the background.However, quit() method can be invoked in order to stop the process after the mainloop() function. We can demonstrate the functionalities of both methods by creating a button Object.Example#Import the required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Set the geometry of frame win.geometry("650x450") #Define a function for Button Object def quit_win(): ... Read More

Difference Between Tkinter and Tkinter.ttk Widgets in Python

Dev Prakash Sharma
Updated on 26-Mar-2021 10:18:53

7K+ Views

tkinter.ttk is a module that is used to style the tkinter widgets. Just like CSS is used to style an HTML element, we use tkinter.ttk to style tkinter widgets.Here are the major differences between tkinter widget and tkinter.ttk −Tkinter widgets are used to add Buttons, Labels, Text, ScrollBar, etc., however, tkinter.ttk supports a variety of widgets as compared to tkinter widgets.Tkinter.ttk doesn't support Place, Pack() and Grid(), thus it is recommended to use tkinter widget with ttk.Ttk has many features and configurations that extend the functionality of a native application and make it look more modern.Tkinter widget is a native ... Read More

Print Name Inside Heart Pattern Using For Loop in C

Bhanu Priya
Updated on 26-Mar-2021 08:03:25

3K+ Views

ProblemWrite a program to print heart shaped pattern with the name in centre using for loop.SolutionThe user has to enter the name that should be printed in centre along with the number of rows the stars has to be print.AlgorithmRefer an algorithm given below to print the name in heart pattern by using for loop.Step 1 − Declare variables.Step 2 − Read a name at runtime that should be printed on centre.Step 3 − Read number of rows.Step 4 − Find the length of name.Step 5 − Print upper part of the heart.Step 6 − Print lower part of the ... Read More

Advertisements