Found 10476 Articles for Python

How to display a Listbox with columns using Tkinter?

Dev Prakash Sharma
Updated on 18-Jun-2021 13:24:28

7K+ Views

To deal with lots of data in any application, Tkinter provides a Treeview widget. It has various features such as displaying data in the form of tables consisting of Rows and Columns.Treeview widget enables the user to add tables, insert data into it, and manipulate the data from the table. The Treeview widget can be constructed by defining the Treeview(parent, column, **options) constructor.Example# Import the required libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter frame win = Tk() # Set the size of the tkinter window win.geometry("700x350") s = ttk.Style() ... Read More

How to open multiple filenames in Tkinter and add the file names to a list?

Dev Prakash Sharma
Updated on 18-Jun-2021 13:24:44

4K+ Views

To open a file dialog in a tkinter application, tkinter provides the tkfiledialog package which creates a dialog box to interact with the external files located on the system. In order to work with filedialog, we have to first import the package using the following command, import tkinter.filedialog as fdTo open the explorer in the window, use asopenfilename(parent, title, **options) function. It will just pull the window and allow the user to select the file from the explorer. Once the file has been opened, we can define a function to print the list of all the selected files.Example# Import the required libraries ... Read More

How to create a directly-executable cross-platform GUI app using Python(Tkinter)?

Dev Prakash Sharma
Updated on 18-Jun-2021 13:13:32

2K+ Views

Python is a programming language which can be used to create cross-platform applications that are supported in various operating systems such as Microsoft Windows, Mac OS, and Linux.To create a GUI-based application, we can use the Tkinter library. However, Python provides different modules and extensions which convert a program into an executable application.For Windows executables - PyInstaller, py2exeFor Linux executables - FreezeFor Max executables - py2appExampleFor this example, we will first install the PyInstaller module using pip in our Windows operating system. The module can be installed by using the command, pip install pyInstallerUsing this module, we will convert our application into ... Read More

How to read multiple text files from a folder in Python?(Tkinter)

Dev Prakash Sharma
Updated on 18-Jun-2021 13:12:49

7K+ Views

Python is capable of handling files, objects, and creating different applications. We can use Python's extensions and packages to build and develop fully featured applications.Suppose you want to control the files in your system; then Python provides an OS Module which has system-enabled functionalities to allow you interact with the files in the operating system.Let us see how we can read multiple text files from a folder using the OS module in Python.Import the OS module in your notebook.Define a path where the text files are located in your system.Create a list of files and iterate over to find if ... Read More

How to plot an area in a Pandas dataframe in Matplotlib Python?

Rishikesh Kumar Rishi
Updated on 18-Jun-2021 10:49:46

3K+ Views

To plot an area in a Pandas dataframe in Matplotlib Python, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a Pandas dataframe, i.e., a two-dimensional, size-mutable, potentially heterogeneous tabular data.Return the area between the graph plots.To display the figure, use show() method.Exampleimport pandas as pd import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(np.random.rand(10, 4), columns=["a", "b", "c", "d"]) df.plot.area() plt.show()Output

How do I show the same Matplotlib figure several times in a single IPython notebook?

Rishikesh Kumar Rishi
Updated on 18-Jun-2021 10:49:02

868 Views

To show the same Matplotlib figure several times in a single iPython notebook, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Plot the data points on that axes.To show the current figure again, use fig.show() method.ExampleIn [1]: %matplotlib auto Using matplotlib backend: Qt5Agg In [2]: import matplotlib.pyplot as plt In [3]: plt.rcParams["figure.figsize"] = [7.50, 3.50] ...: plt.rcParams["figure.autolayout"] = True In [4]: fig, ax = plt.subplots() In [5]: ax.plot([2, 4, 7, 5, 4, 1]) Out[5]: [] In [6]: fig.show()Output

How to plot sine curve on polar axes using Matplotlib?

Rishikesh Kumar Rishi
Updated on 18-Jun-2021 10:48:29

735 Views

To plot the sine curve on polar axes, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure using figure() methodAdd an '~.axes.Axes' to the figure as part of a subplot arrangement.Get x and y data points using numpy.Plot x and y data points using plot() method.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_subplot(projection='polar') x = np.linspace(-5, 5, 100) y = ... Read More

How do I find the intersection of two line segments in Matplotlib?

Rishikesh Kumar Rishi
Updated on 18-Jun-2021 10:48:02

7K+ Views

To find the intersection of two lines segments in Matplotlib and pass the horizontal and vertical lines through that point, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create two lines using slopes (m1, m2) and intercepts (c1 and c2). Initialize the slopes and intercept values.Create x data points using numpy.Plot x, m1, m2, c2 and c1 data points using plot() method.Using intercepts and slope values, find the point of intersection.Plot the horizontal and vertical lines with dotted linestyle.Plot xi and yi points on the plot.To display the figure, use ... Read More

How to show minor tick labels on a log-scale with Matplotlib?

Rishikesh Kumar Rishi
Updated on 18-Jun-2021 10:47:30

8K+ Views

To show minor tick labels on a log-scale with Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Plot x and y data points using plot() methodGet the current axis using gca() method.Set the yscale with log class by name.Change the appearance of ticks and tick label using ick_params() method.Set the minor axis formatter with format strings to format the tick.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt from matplotlib.ticker import FormatStrFormatter plt.rcParams["figure.figsize"] = [7.50, 3.50] ... Read More

How to hide lines in Matplotlib?

Rishikesh Kumar Rishi
Updated on 18-Jun-2021 10:47:07

4K+ Views

To hide lines in Matplotlib, we can use line.remove() method.StepsSet the figure size and adjust the padding between and around the subplots.Create x, y1 and y2 data points using numpy.Make lines, i.e., line1 and line2, using plot() method.To hide the lines, use line.remove() method.Place a legend on the figure at the upper-right location.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-10, 10, 100) y1 = np.sin(x) y2 = np.cos(x) line1, = plt.plot(x, y1, label="Line 1") line2, = plt.plot(x, y2, label="Line 2") ... Read More

Advertisements