Found 310 Articles for GUI-Programming

How to remove the dashed line from the Tkinter menu UI?

Dev Prakash Sharma
Updated on 25-May-2021 09:13:49

841 Views

A Menu Bar contains vertically stacked menu items. We can create a Menu bar by initializing the object of Menu(root). Whenever we initialize a Menu bar in an application, it displays a line separator at the top of the Menu Bar.To remove the separator or the dashed line from the Menu, we can use the tearoff property. It can be created by defining the 'tearoff = off' property.Example#Import the required Libraries from tkinter import * from tkinter import ttk #Create an instance of Tkinter frame win = Tk() #Set the geometry of Tkinter frame win.geometry("750x250") win.title("Editor") # Adding ... Read More

How to center a Tkinter widget?

Dev Prakash Sharma
Updated on 25-May-2021 09:12:56

12K+ Views

Tkinter widgets are customizable by specifying their properties, for example, width, height, position, background color, etc. To position the Tkinters widgets, we can use place() geometry manager, where we will specify the anchor property. It can take (NW, N, NE, W, CENTER, E, SW, S, SE) as the position of the widget.ExampleIn this example, we have forced a Label widget to the center of the window by specifying the anchor property.#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='#4fe3a5') ... Read More

How to get the width of the Tkinter widget?

Dev Prakash Sharma
Updated on 25-May-2021 09:12:21

8K+ Views

Tkinter widgets are supposed to be present in the Tkinter application window. All the widgets can be configured and customized by using predefined properties or functions.To get the width of a widget in a Tkinter application, we can use winfo_width() method. It returns the width of the widget which can be printed later as the output.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='#aad5df') #Create a Label to display the text label=Label(win, text= "Hello World!", font= ... Read More

Read an image with OpenCV and display it with Tkinter

Dev Prakash Sharma
Updated on 25-May-2021 09:11:47

5K+ Views

OpenCV is an Open Source Computer Vision library in Python which is widely used for Research purposes in Artificial Intelligence and Machine Learning. Computer Vision Library such as OpenCV deals with image processing. We can use OpenCV to read an image and further use it for development.Let us suppose that we want to create an application that reads an image and displays it in the window using OpenCV.Install OpenCV by using the following command −pip install opencv-pythonNext, follow the steps given below −Install OpenCV in the environment and import the library using import cv2.Import NumPy and PIL (Pillow Package) for image calculation.Load ... Read More

How to keep the window focus on the new Toplevel() window in Tkinter?

Dev Prakash Sharma
Updated on 25-May-2021 09:11:27

5K+ Views

Tkinter toplevel class contains toplevel window which is a child window other than the main window. Whenever we create a toplevel window, it just appears above the main window along with the widgets defined in it.To keep the window toplevel window focused, we can use grab_set() method. It always keeps the toplevel window above all the other windows.Example#Import the tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() win.geometry("700x350") def open_win():    top = Toplevel(win)    top.geometry("700x250")    Label(top, text= "Hey Folks!", font= ('Helvetica 14 bold')).pack()    top.grab_set() #Create a Label to print the ... Read More

Hide the console of an .exe file created with PyInstaller in Tkinter

Dev Prakash Sharma
Updated on 25-May-2021 08:56:17

11K+ Views

To convert a standard Tkinter application into a window executable file, we generally use thePyintsaller package. It converts the application file into an executable application. However, we notice that when we open the executable (or .exe) file, it displays a command shell before opening the application window. We can hide or avoid the console by specifying pyinstaller --oneline filename --windowed command.ExampleIn this example, we will create an .exe file of the following program using PyInstaller.app.py#Import the required libraries from tkinter import * #Create an instance of Tkinter Frame win = Tk() #Set the geometry win.geometry("700x350") #Set the ... Read More

How to remove the icon from the title bar in Tkinter?

Dev Prakash Sharma
Updated on 25-May-2021 08:52:26

3K+ Views

To remove the default icon of the Tkinter window, we can use wm_attributes('type', 'value') method by specifying the type of property. In the following example, we will use '-toolwindow', a Boolean value that removes the icon associated with the title bar of the application.Example#Import the tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() win.geometry("700x350") #Create a Label to print the Name label= Label(win, text="This is a New Line Text", font= ('Helvetica 14 bold'), foreground= "red3") label.pack() win.wm_attributes('-toolwindow', 'True') win.mainloop()OutputWhen we run the above code, it will display a Tkinter window ... Read More

How to remove the title bar in a Tkinter window without using overrideredirect() method?

Dev Prakash Sharma
Updated on 25-May-2021 08:51:14

6K+ Views

To remove the title bar of a Tkinter window, we can use wm_attributes('type', 'value') method by specifying the type of property. In the following example, we will use 'fullscreen', a Boolean value that removes the title bar of the window.Example#Import the tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() win.geometry("700x350") #Create a Label to print the Name label= Label(win, text="This is a New Line Text", font= ('Helvetica 14 bold'), foreground= "red3") label.pack() win.wm_attributes('-fullscreen', 'True') win.mainloop()OutputRunning the above code will display a fullscreen window without the title bar.Read More

What's the difference between Tkinter's Tk and Toplevel classes?

Dev Prakash Sharma
Updated on 25-May-2021 08:50:56

893 Views

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 ... Read More

Default window color Tkinter and hex color codes in Tkinter

Dev Prakash Sharma
Updated on 25-May-2021 08:50:36

1K+ Views

A Tkinter window can be customized by adding the properties and attributes such as background color, foreground color, width, height, etc.The color attribute in config() defines the default color of the main window. We can set the color of the window by defining either Hex Color (e.g., #000 for Black) or the Name of the color. The supported Tkinter color chart can be found hereExample# 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 = '#24f3f0') # ... Read More

Advertisements