Found 310 Articles for GUI-Programming

How to make a new folder using askdirectory dialog in Tkinter?

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 12:25:13

2K+ Views

To make a new folder using askdirectory dialog in Tkinter, we can take the following steps −Import the required modules. filedialog module is required for askdirectory method. os module is required for makedirs method.Create an instance of tkinter frame.Set the size of the frame using win.geometry method.Define a user-defined method "create_subfolder". Inside the method, call filedialog.askdirectory to select a folder and save the path in a variable, source_path.We can use askdirectory method of filedialog to open a directory. Save the path of the selected directory in a 'path' variable.Then, use os.path.join and makedirs to create a sub-folder inside the parent ... Read More

How to change the size of text on a label in Tkinter?

Dev Prakash Sharma
Updated on 06-Aug-2021 07:49:05

21K+ Views

The label widget in Tkinter is used to display text and images in a Tkinter application. In order to change the properties of the label widget such as its font-property, color, background color, foreground color, etc., you can use the configure() method.If you want to change the size of the text in a Label widget, then you can configure the font=('font-family font-size style') property in the widget constructor.Example# Import the required libraries from tkinter import * import tkinter.font as tkFont # Create an instance of tkinter frame or window win=Tk() # Set the size of the tkinter window ... Read More

How to use the Entry widget in Tkinter?

Dev Prakash Sharma
Updated on 06-Aug-2021 07:44:00

2K+ Views

The Entry widget is a single-line text widget defined in Tcl/Tk toolkit. We can use the Entry widget to accept and display single-line user input.In order to use the Entry widget, you have to first create an Entry widget using the constructor Entry(parent, width, **options). Once we've defined our Entry widget, we can configure its properties such as font-properties, color, width, etc., using the configure() method.ExampleLet use create an Entry widget to accept the username and display it in the window.# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win ... Read More

How to create a Tkinter error message box?

Dev Prakash Sharma
Updated on 06-Aug-2021 07:40:41

16K+ Views

The Tkinter library has many built-in functions and methods which can be used to implement the functional part of an application. We can use messagebox module in Tkinter to create various popup dialog boxes. The messagebox property has different types of built-in popup windows that the users can use in their applications.If you need to display the error messagebox in your application, you can use showerror("Title", "Error Message") method. This method can be invoked with the messagebox itself.Example# Import the required libraries from tkinter import * from tkinter import messagebox # Create an instance of tkinter frame or window ... Read More

How to change Tkinter label text on button press?

Dev Prakash Sharma
Updated on 06-Aug-2021 07:29:13

9K+ Views

Most often, Tkinter Label widgets are used in the application to display the text or images. We can configure the label widget such as its text property, color, background or foreground color using the config(**options) method.If you need to modify or change the label widget dynamically, then you can use a button and a function to change the text of the label widget.Example# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win = Tk() # Set the size of the tkinter window win.geometry("700x350") # Define a function update ... Read More

How to reconfigure Tkinter canvas items?

Dev Prakash Sharma
Updated on 06-Aug-2021 06:45:03

8K+ Views

Using the Canvas widget, we can create text, images, graphics, and visual content to add to the Canvas widget. If you need to configure the Canvas item dynamically, then tkinter provides itemconfig(**options) method. You can use this method to configure the properties and attributes of the Canvas items. For example, if we create a line inside the Canvas widget, we can configure its color or width using itemconfig() method.Example# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win = Tk() # Set the size of the tkinter window win.geometry("700x350") ... Read More

How to set justification on Tkinter Text box?

Dev Prakash Sharma
Updated on 06-Aug-2021 06:40:30

3K+ Views

The Text widget supports multiline user input from the user. We can configure the Text widget properties such as its font properties, text color, background, etc., by using the configure() method.To set the justification of our text inside the Text widget, we can use tag_add() and tag_configure() properties. We will specify the value of "justify" as CENTER.Example# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win=Tk() # Set the size of the tkinter window win.geometry("700x350") # Create a text widget text=Text(win, width=40, height=10) # justify the text ... Read More

How to get the widget name in the event in Tkinter?

Dev Prakash Sharma
Updated on 06-Aug-2021 06:37:34

2K+ Views

Tkinter is a Python library that is used to create and develop functional GUI-based applications. Tkinter provides widgets that can be used for constructing the visual and functional representation of the application.Let us suppose that we have defined some widgets in our application. If we want to get a widget's name in an event, then it can be achieved by using event.widget["text"] keywords inside a function. We can print the name by using it inside the print() function.Example# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win=Tk() # Set ... Read More

How to delete lines from a Python tkinter canvas?

Dev Prakash Sharma
Updated on 06-Aug-2021 06:34:33

3K+ Views

The Canvas widget has many use-cases in GUI application development. We can use a Canvas widget to draw shapes, creating graphics, images, and many other things. To draw a line in Canvas, we can use create_line(x, y, x1, y1, **options) method. In Tkinter, we can draw two types of lines − simple and dashed.If you want your application to delete the created lines, then you can use the delete() method.ExampleLet us have a look at the example where we will delete the line defined in the Canvas widget.# Import the required libraries from tkinter import * # Create an ... Read More

How to insert the current time in an Entry Widget in Tkinter?

Dev Prakash Sharma
Updated on 06-Aug-2021 06:31:55

2K+ Views

To work with the date and time module, Python provides the 'datetime' package. Using the 'DateTime' package, we can display the date, manipulate the datetime object and use it to write the additional functionality in the application.To display the current date in a Tkinter window, we've to first import the datetime module in our environment. Once imported, you can create an instance of its object and display it using the Entry widget.ExampleHere is an example of how you can show the current date in an Entry widget.# Import the required libraries from tkinter import * import datetime as dt ... Read More

Previous 1 ... 7 8 9 10 11 ... 31 Next
Advertisements