Python Desktop Application That Displays Your Computer’s System Properties

Rümeysa Nur Arık
14 min readAug 29, 2022
drawn by artificial intelligence

In this article, I will explain how you can learn the system features of your computer (ram, disk, gpu, etc.) by developing a Python desktop application.

The program we wrote gives us the following information about the system properties:

HOME page provides the user with basic information such as
computer name, operating system, operating system type, version and ram information
(size).

The CPU page contains the following information:
*processor
*Speed
*Base Speed
*Percentage of usage
*Number of Logical Processors
*Number of Cores
**There is also a graph of “Percentage Usage” on the CPU page.

The GPU page contains the following information:
*Brand/Model
*Memory Amount
*Refresh Rate
*Graphic Architecture

The RAM page contains the following information:
*Brand/Model
*Part number
*Total Memory Amount
*Memory Used
*Available Memory
*Speed
*Max Speed
*Percentage of Usage
**There is also a graph of “Percent Usage” on the RAM page.

The DISK page contains the following information:
*Disk
*Type
*File System
*Total area
*Used Area
*Available Space
**There is also a “Used Space and Usable Space” graphic on the DISK page.

The NETWORK page contains the following information:
*Description

*Physical Address

*State

*SSID

*BSSID

*Radio Type

*Signal

*Profile

While I was writing the program, I preferred to use “Visual Studio Code” because it provides easy use and compatibility.

Let’s move on to the code of the program.

We have two main Python files. In one of them (Main.py) our main function and interface has design.In the other file (System Info.py), there are libraries, modules and functions that we use to get system information from the computer.The reason why we write in two different Python files is to avoid confusion and to provide a cleaner code view.

First, let’s examine the SystemInfo file and the codes it contains.In this Python file, we need some modules and special libraries, as we will pull system information from the computer. Modules and libraries we will use:

Modules and libraries

After adding the library and modules, let’s write the functions to get the information that should appear on the HOME page from the computer. First we create a class. The name of our class is System information. Inside this class will be the information we want to display on the HOME page.

class System Information()

With the VMI module, we got the information about the windows version, the total amount of memory, the windows version number and how many bits the operating system is.We preferred the “platform library” to access only the computer name information.

Home page

In Python, a function is defined using the def keyword. We defined our functions using this method.

Now let’s create a class where we get the information we want to see on the CPU page from the computer.

class CPU_information

This time we used both WMI moduleand psutil.

CPU page

Again, we create functions with def. We used wmi module for cpu name only. We pulled the other information through psutil. Other information: CPU usage percentage, base speed, max speed, number of cores, number of logical processors.

Next up is the GPU page. We create a class again. Actually basically our code writing logic is the same.

class GPU_information

Again we used WMI.The VMI module is very important for us.

GPU page

*Returns the list of video card names. In this way, we will be able to see the graphics card names, respectively, in the combobox that we will create on the GPU page in the Main.py file in the future.

**Returns the properties of graphics cards by name as a dictionary. This way we keep the information in valueDict= dict() and when we call information from this function we get a direct response.

Thus, we pulled the name, memory amount, screen refresh rate, graphic architecture information from the computer.

Next is the RAM page. We create our class and use wmi module and psutil.

class Memory_information

Then we write the functions from which we pull the information.

RAM page

We pulled all the information you see in the code above from the computer.

We will create our fifth class and get DISK information.

class Disk_information

We continue to use vmi module and psutil.

DISK page

Here we are returning a list for different disks as we did before. The dict element allowed us to return properties based on our disk names.

DISK page

Finally, for the NETWORK page;

class Network_information

pass element is something we write because we don’t need to use a ready-made library or module.

The difference of the Network page from other pages is that we get the information directly from cmd (command prompt) without using any module or library.

When you type “netsh wlan show interface” and run it, you will see the following output in the command prompt.

cmd output

When we want to add this list starting with “Name” and ending with “Profile” in our own code, Python sees it as a single string value. But we don’t want to include all the information found here in the code.

In addition, while designing the interface in the Main.py file in the future, we keep every information on the NETWORK page in different widgets and tags. In its current form, it’s not something we want to add directly to the code.

Below are functions that do what we want.

NETWORK page

We add spaces as seen above.

NETWORK page

The last part is the key list where we keep all the categories in it.

This is how we completed our SystemInfo.py file. Our job of pulling the information from the computer is completely done. Now we can move on to the codes of the Main.py file to create an application interface and transfer it to the interface we created.

THE INTERFACE

First of all, the libraries and modules we will use:

Modules and libraries

We said that we will pull the information from the “SystemInfo.py” file. Now we add the classes we created in SystemInfo.py to our code to pull the information.

classes

Then we create a main class. Then we create a function for creating the main window, window title, window size. Here we also use def .

class Main(QMainWindow)

For the “self.Key = True “graphic loop to work, we’ll refer to it later. “app.about To Quit.connect(self.close Event)” we will refer to the loops we will make to close and terminate the program.

As we mentioned in the comment line above, we assign the classes to the variables we have specified. “Self.style” is a class that we will create later, but we can see it now because variable assignment operations are done in this block.

self.Interface()

The basic skeleton of the interface is created with self.Interface() . “Self.Homepage Func()” is the function we use when creating the page. We do the same for each page.The function we wrote to open the self.show window.

The “self.Live LoadPercentage()” item allows to add data continuously, for example for graphics in CPU and RAM. We’ll talk about it later.

self.show()

In this function, we align two “QLabels (nameLabel, resultLabel)” side by side using “QHBoxLayout” and throw them into a widget. It returns the “wigdet(QWidget)” every time the function is used.We created a function to avoid writing the same code every time. Because these processes would require us on every page. We just specified a size for “nameLabel”.

We set the height as 50 for the widget. As a result, this function we created added two labels in a “widget” and aligned them side by side.

def Interface(self)

There are two parts to appear in our program: Left menu and pages. When we make a selection from the left menu, we want the page we selected on the right to appear.

We added the interface pages within the Interface() function ,we created widgets for each page.

Left menu(Toolbar)

We wrote our functions as above to call the item with the left menu interactively by adding Actions to it.We have also done the adding of icons here.

“self.addToolBar(Qt.LeftToolBarArea, self.LeftMenu ToolBar)”We have added the left menu to the interface by using the function. Then we added a button so that we can choose from the left menu. Added a button for each page.

resizing actions

We did the sizing as above.

binding actions to functions

We connected a function to each of the actions so that when we click to make a selection from the left menu, the page opens. For example, when we click the HOME button, the HOME page should open.

adding to interface

We have seen the Style Class in the classes section before. It would be right to talk about this class here.

class StyleClass

In this class, we define the design properties of the elements in the interface. The reason for creating this class is to allow the design of the interface elements to be changed at once by creating functionsYou can find this class there because we add the classes to the beginning of the code.

After adding to the interface, we can now start making page designs.

home page design

HOME page looks like this.

While designing, we first write how much information there is in the text separately. “VBox0” item aligns the Labels on top of each other. We used the “self.SysInfo.get WindowsName()” structure to sort it line by line, as the name suggests, which pulls information from the SystemInfo.py file.

At this point, we take a break from page design.

Here we create a function for the graphics that we will use on some pages.Our graphics work based on 60 seconds, so we created a function where we adjust the timing accordingly.In other words, we have provided a data assignment every second in our graphs. We will see this in the graph creation section in the future.

time adjustment
CPU and RAM

We then wrote functions to get it as a percentage.

max 60 values

Since our charts are based on 60 seconds, we need to make room for the 61st value. Therefore, we delete the first value and add the 61st value instead. In this way, our list is arranged to have a maximum of 60 elements. This process is repeated for each new value. Now we will create the graphics we mentioned earlier in the Project Scope. These are the percentage usage graphs found on the CPU and RAM page.

CPU and RAM graphs

We created the “Mpl Canvas class” to add the features we determined while creating the graphics.This class has the necessary features to interactively add the graphics we created using the “mathplotlib” library to the interface. At the same time, “MlpCanvas” allows us to customize the graphic we get.

The operations seen in the code snippet above allow us to specify the color, text style, background color, etc. of the graphic.

class MplCanvas()

Here we see the contents of the Mpl Canvas class.

We continue with the page design. CPU page layout:

CPU page
CPU page

The CPU Page Func() function displays the properties of the CPU unit.
Here, we repeat a “CreatinLabelinWidget”-like structure only for these time-dependent values, since the content of the CPU page will show time-dependent changes (animated graphics, etc.).

We use the functions inside the “CPUInformation” class, where we assign these values to the “self.CPUInfo” variable. At the same time, we use the variable “self.CPUInfo” for information that is fixed. We position the interface elements using “VBox” and “HBox”. In the interface design we created, we add “self.CPU” into the widget element.

This is how the CPU page looks in the program.

CPU page

Next is the design of the GPU page.

GPU page design

In GPU Page Func, the graphics card name list is added to the QCombobox. Connecting to the “QComboBox” GPU Replacement function.

GPU page

GPU Replacement function by value in “combobox”
“GPU Information” that we assigned to the “self.GPUInfo” variable
By giving the necessary parameters to the functions inside the class and aligning the returned values with the help of “VBox”
It adds it into the “QMainWindow” that we assigned to the “self.GPU MainWindow” variable. Thus, the features that we have determined according to the name of the graphics card are reflected in the interface.
This is how the GPU page looks in the program.

GPU page

Now we can move on to the design of the RAM page.

RAM page

We are doing the same things we did on the GPU page here.

RAM page

Above, we only make the positioning on the page using VBox and HBox.

This is how the RAM page looks in the program.

RAM page

Next is the design of the DISK page.

def DISK_Page_Func(self)

The DISK Page Func function, which has a similar structure to the GPU Page Func function, adds the names of the disks in the computer system into a “QComboBox”.
According to these names, some features of the discs are shown on the page. In addition, error management is carried out by using the try-excet structure so that no errors occur in the program when any disk is inserted or removed from the computer.

If an error occurs in the program, thanks to this structure, the program does not perform the wrong operation, but the program
does not prevent it from continuing to work.
(The error management will print the error message to the console, depending on the error that will occur in the program.
This information is only visible to the program developer.)

Continuation of the code:

DISK page
DISK page

This is how the DISK page looks in the program.

DISK page

The design of the NETWORK page:

NETWORK page

And so it goes.

NETWORK page

In the “NETWORK Page Func” function, as in other PageFuncs, it reaches the functions within the class of the Network section and reflects the features of some wired / wireless network connections of the computer to the interface. When the QPushButton assigned to the “self.NETWORK RefleshButton” variable, which is linked to the “NETWORK Replacement” function, is clicked here, these features are renewed. Thus, every time the Refresh button is clicked, the information on the page is refreshed.

This is how the Network page looks in the program.

NETWORK page
def closeEvent(self,event)

The “closeEvent” function breaks/ends the loops inside the program when the program is closed. This process makes the value of self.Key, which we mentioned before, “False” and runs other necessary ready-made functions for the termination of the program. Thus, the program is terminated. (In short, the actions that take place when the Quit button of the window is clicked.)

last code

In the if block above, there are all the necessary functions to run our Main() class and keep it running.

Thus, the process of writing the code of the program is finished.

I got the icons I use from “Flaticon”. You can also use the icons there.

You can visit my Github account for program files and details.

Thank you for reading,I hope it was helpful.

https://github.com/

www.linkedin.com/in/

MY REFERENCES

--

--