Found 26504 Articles for Server Side Programming

Python Program to Construct a Tree & Perform Insertion, Deletion, Display

AmitDiwan
Updated on 15-Apr-2021 13:47:54

631 Views

When it is required to construct a binary tree, and perform operations such as inserting an element, deleting an element and displaying elements of the tree, a class is defined with methods in it. An instance of the class is defined and this is used to access the elements and perform operations.Below is a demonstration of the same −Example Live Democlass Tree_struct:    def __init__(self, data=None, parent=None):       self.key = data       self.children = []       self.parent = parent    def set_root(self, data):       self.key = data    def add_node(self, node): ... Read More

Check whether a number has consecutive 0’s in the given base or not using Python

AmitDiwan
Updated on 15-Apr-2021 13:44:27

208 Views

When it is required to check if a number has consecutive zeroes of a specific base, a method is defined, that takes the number and base as parameters, and uses another method to return Yes or No depending on whether the base is present or not.Below is a demonstration of the same −Example Live Demodef check_consecutive_zero(N, K):    my_result = convert_to_base(N, K)    if (check_n(my_result)):       print("Yes")    else:       print("No") def convert_to_base(N, K):    weight = 1    s = 0    while (N != 0):       r = N % K   ... Read More

How do I 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

Program to Implement Queue in Python

AmitDiwan
Updated on 15-Apr-2021 13:43:53

1K+ Views

When it is required to implement a queue using Python, a queue class is created, and methods to add and delete elements are defined. An instance of the class is created, and these methods are called using the instance and relevant output is displayed.Below is a demonstration of the same −Example Live Democlass Queue_struct:    def __init__(self):       self.items = []    def check_empty(self):       return self.items == []    def enqueue_elem(self, data):       self.items.append(data)    def dequeue_elem(self):       return self.items.pop(0) my_instance = Queue_struct() while True:    print('Enqueue ') ... Read More

Python Program to Implement a Stack

AmitDiwan
Updated on 15-Apr-2021 13:43:28

4K+ Views

When it is required to implement a stack using Python, a stack class is created, and an instance of this class is created. Methods to push, pop elements are defined and the instance is used to call these methods.Below is a demonstration of the same −Example Live Democlass Stack_struct:    def __init__(self):       self.items = []    def check_empty(self):       return self.items == []    def add_elements(self, my_data):       self.items.append(my_data)    def delete_elements(self):       return self.items.pop() my_instance = Stack_struct() while True:    print('Push ')    print('Pop')    print('Quit')   ... Read More

How do I 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

How can I 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

How can I display an 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

How can I disable typing in a ttk.Combobox 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 the 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