
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10476 Articles for Python

3K+ Views
To put text outside a plot, we can change the text position by changing the value of text_pos_x and text_pos_yStepsCreate data points for x and y.Initialize the text position of x and y.To plot x and y, use plot() method with color='red'.Use text() method to add text to figure.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(1, 5, 100) y = np.exp(x) text_pos_x = 0.60 text_pos_y = 0.50 plt.plot(x, y, c='red') plt.text(text_pos_x, text_pos_y, "$\mathit{y}=e^{x}$", fontsize=14, transform=plt.gcf().transFigure, color='green') plt.show()OutputRead More

628 Views
To plot a confusion matrix with string axis rather than integer in Python, we can take the following steps−Make a list for labels.Create a confusion matrix. Use confusion_matrix() to calculate accuracy of classification.3. Add an '~.axes.Axes' to the figure as part of a subplot arrangement.Plot the values of a 2D matrix or array as a color-coded image.Using colorbar() method, create a colorbar for a ScalarMappable instance, *mappable*6. Set x and y ticklabels using set_xticklabels and set_yticklabels methods.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt from sklearn.metrics import confusion_matrix plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True labels ... Read More

31K+ Views
Lamda Functions (also referred to as Anonymous Function in Python) are very useful in building Tkinter GUI applications. They allow us to send multiple data through the callback function. Lambda can be inside any function that works as an anonymous function for expressions. In Button Command, lambda is used to pass the data to a callback function.ExampleIn this example, we will create an application that will have some buttons in it. The button command is defined with the lambda function to pass the specific value to a callback function.#Import the library from tkinter import * from tkinter import ttk ... Read More

3K+ Views
Tkinter LabelFrame is similar to Frames in Tkinter Library. It works like a container where widgets can be placed. LabelFrame initially creates a container with some rectangular border around it. In order to style the LabelFrame widget, we have several style options such as background, borderwidth, labelanchor, highlightcolor and many more.ExampleIn this example, we will see the LabelFrame widget and its properties.#Import required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Define the geometry of the window win.geometry("750x250") #Initialize a LabelFrame Widget labelframe= LabelFrame(win, text= "Frame 01", width= 600, height= 200, labelanchor= "n", font= ('Helvetica ... Read More

3K+ Views
Tkinter Button widgets are very useful in terms of handling events and performing actions during the execution of an application. We can create Tkinter Buttons using the Button(parent, text, option..) constructor. Using the constructor, we can create multiple buttons within the loop.ExampleIn this example, we will create multiple buttons in the range using a Python for loop.#import required libraries from tkinter import * from tkinter import ttk #Create an instance of Tkinter frame win= Tk() #Set the geometry of the window win.geometry("750x250") #Create a LabelFrame labelframe= LabelFrame(win) #Define a canvas in the window canvas= Canvas(labelframe) canvas.pack(side=RIGHT, fill=BOTH, ... Read More

5K+ Views
In order to work with a tkinter application, we have to install and import the tkinter library in our environment. Generally, we import the tkinter library in the environment by using from tkinter import * command.The significance of "import *" represents all the functions and built-in modules in the tkinter library. By importing all the functions and methods, we can use the inbuilt functions or methods in a particular application without importing them implicitly.There are lots of widgets, functions, methods available in tkinter library which can be used to construct the component of a particular application. Tkinter provides the ttk ... Read More

9K+ Views
Tkinter is a Python package which comes with many functions and methods that can be used to create an application. In order to create a tkinter application, we generally create an instance of tkinter frame, i.e., Tk(). It helps to display the root window and manages all the other components of the tkinter application. We can initialize the tkinter instance by assigning the variable to it.ExampleIn the following example, we will create an instance of tkinter frame and create a label widget.#Import tkinter library from tkinter import * #Create an instance of tkinter frame or window win= Tk() #Set the ... Read More

4K+ Views
Tkinter variable (var) is defined for a particular widget (textvariable=var) to store the updated value of a widget. Sometimes, there might be a case, while updating the variable information, we need to process some extra operations such as read, write, or undefined.Tkinter provides a way to update the variable with a callback function trace (self, mode, callback) which takes the operation of the process such as read(r), write(w), or undefined(u). On the basis of these values, the callback decides what the process needs to do in the callback function. The other two values define the variable which needs to be ... Read More

17K+ Views
Tkinter is a Python library used for creating and developing GUI-based applications. It is completely open-source which works on Windows, Mac, Linux, and Ubuntu. In Windows operating system, we can install the Tkinter library using the command pip install tkinter. It will install all the other modules that come with Tkinter library. Tkinter can be installed on Jupyter notebook as well, by using the command pip install tkinter. We can run all the standard commands of Tkinter in Jupyter notebook.Once we have installed Tkinter in Jupyter notebook, then we can verify the installation by typing the following command −from tkinter ... Read More

4K+ Views
Tkinter Spinbox is used to add the increment and decrement buttons to the Entry widget, making it useful to handle the numerical data of any application. A spinbox widget can be created using the Spinbox(arguments). We can set the default value for the spinbox widget by defining the Value using StringVar() object. The default value plays a vital role for any widget, as it helps you to define the bounded value.Example#Import Tkinter library from tkinter import * from tkinter import ttk #Create an instance of Tkinter frame or window win= Tk() #Set the geometry of tkinter frame win.geometry("750x250") #Set the ... Read More