Hello Python Developer!
How are you? Hope you're in the best condition today. Because we will exercise PyQt WIndow setup.
-PyQt wIndow Size adjustment
- PyQt titlebar & icon setting
Hello Python Developer!
How are you? Hope you're in the best condition today. Because we will exercise PyQt WIndow setup.
-PyQt wIndow Size adjustment
Hello Python developer!
Do you want to code a window base GUI(Graphic User Interface) app like below image?
'PyQt' made by Riverbank Computing and you can find latest news and more details about PyQt from the following link.
PyQt site : https://riverbankcomputing.com/software/pyqt/
For installation of PyQt library at your PC, please type following command in Windows command prompt.
pip install pyqt5
Are you ready for the first PyQt coding?
Let's input following code for PyQt sample and run it!
import sys
from PyQt5.QtWidgets import *
app = QApplication(sys.argv)
label = QLabel(" Hello GUI by Python! ")
label.show()
app.exec_()
Hello Python developer!
Hope you're good today with bright sunshine like our future!
Today, I would like to study Initializer method in Python Class.
Class initializer method was made for initiating class variables and methods.
Think about this, if you create an instance from the class and you want it to have each initiate values and functions.
For instance, we will make a calculator Python program.
First, we will initialize the calculator result variable as 0 with initializer method using ' def __init__(self): ' statement.
Let's look into the following codes.
class Calculator:
def __init__(self):
self.result = 0
def add(self, var1, var2):
self.result = var1 + var2
return self.result
def sub(self, var1, var2):
self.result = var1 - var2
return self.result
test_add = Calculator()
test_sub = Calculator()
print(test_add.add(4, 7))
test_sub.sub(7, 2)
print(test_sub.sub(9,6))
If you want to transfer variables into initializer method, refer following statement.
def __init__(self, var1, var2):
self.first_var = var1
self.second_var = var2
Now, are you familiar with the class 'Initializer' method?
Then, let's analyze following Python exercise codes.
# Python initiate method exercise
class Smartphone:
def __init__(self, model, year): # initiate class 'Smartphone' with following variables and function
self.model = model
self.year = year
self.model_year = model + " " + str(year)
Apple_phone = Smartphone("iPhone 14", 2022)
Samsung_phone = Smartphone("Galaxy S23", 2023)
print(Apple_phone.model, Apple_phone.year)
print(Samsung_phone.model, Samsung_phone.year)
print(Apple_phone.model_year)
print(Samsung_phone.model_year)
Here is above Python source codes in Github(https://github.com/Cevastian/Python-Developer-start-today/blob/master/Python_initiate_method.py)
Hope you get the right answer and level up your Python class understanding.
See you at the next post! Take care!
Hello Python developer!
Today, we will look into class 'inheritance' with my test codes. Because I want to understand about 'class inheritance'.
Let's see following codes and type in Python IDE for execution!
Source codes(Multi_Inheritance.py)
Github link : https://github.com/Cevastian/Python-Developer-start-today/blob/master/Multi_Inheritance.py
class Lion():
color = "yellow"
classification = "animal"
def hunting(self):
print("Lion is hunting")
def attack_claw(self):
print("Claw attack")
class Eagle():
color = "brown"
classification = "bird"
def hunting(self):
print("Eagle is hunting")
def attack_beak(self):
print("Beak attack")
class Shark():
color = "blue"
classification = "fish"
def hunting(self):
print("Shark is hunting")
def attack_teeth(self):
print("Teeth attack")
class Monster(Lion, Eagle, Shark):
color = "green"
classification ="beast"
def playing(self):
print("Monster is playing")
def attack_tail(self):
print("Tail attack")
monster = Monster() # Class instance generating
monster.playing() # monster instance playing method calling
monster.hunting() # monster instance 'Lion' class 'hunting' method by inheritance
monster.attack_teeth() # monster instance 'Shark' class 'attack_teeth' method by inheritance
Executed result
So, 'monster.hunting' method execution result was 'Lion' classes' method excution result. Because there is no 'hunting' method in 'Monster' class so Python search 'hunting' method from the parent classes by 'Lion', 'Eagle' and 'Shark' sequence by Monster(Lion, Eagle, Shark) class inheritance.
Developer, did you understand 'class inheritance' with above example?
Hope you're fine today with Python codes!
Hello, Python developer!
Hope you're fine today! Do you know how can we express the current time in Python program?
Python has 'datetime' module for dealing with the date and time.
Let's test the it with following codes.
Hello Python developer,
Today, I will code Bitcoin price checker with requests module.
Python module is file set of python codes - functions.
I showed module declaration from the Python Glossary
(https://docs.python.org/3/glossary.html#term-module)
import Python module name
We will use 'requests' module for web-scrapping from the 'Binance' cryptocurrency exchange.
Here is the executed result.
There are two ways to print out the Bitcoin price.
- Print content variable from the current_price
- Using JSON module with json function to print out the current Bitcoin price
I also uploaded this code in my GibHub.
I hope you to enjoy above codes.
Have a nice day, Python developer!
Hello, Developer!
Today, I will exercise about Python 'Class'.
Class is based on OOP(Objective Oriented Programming) and I need to exercise it with several examples about class for clear understanding.
Did you remember about 'Class'?
It consists of two parts - Data and Function as following image. Normally, developers call 'data' in class as 'attribute' and 'function' in class as 'method'.
Hello Python developer! How are you? Hope you've been good and had wonderful time with Python. There are 10 Python requests module exerc...