Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions Modul5/DemoQCheckBox/DemoQCheckBox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import sys
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class MainForm(QWidget):
def __init__(self):
super().__init__()
self.setupUi()

def setupUi(self):
self.resize(300, 100)
self.move(300, 300)
self.setWindowTitle('Demo QCheckBox')
self.label = QLabel()
self.label.setText('Tentukan pilihan Anda:')
self.perlCheck = QCheckBox()
self.perlCheck.setText('Perl')
self.pythonCheck = QCheckBox()
self.pythonCheck.setText('Python')
self.rubyCheck = QCheckBox()
self.rubyCheck.setText('Ruby')
self.phpCheck = QCheckBox()
self.phpCheck.setText('PHP')
hbox1 = QHBoxLayout()
hbox1.addWidget(self.perlCheck)
hbox1.addWidget(self.pythonCheck)
hbox1.addWidget(self.rubyCheck)
hbox1.addWidget(self.phpCheck)
self.okButton = QPushButton('&OK')
self.exitButton = QPushButton('Keluar')
hbox2 = QHBoxLayout()
hbox2.addStretch()
hbox2.addWidget(self.okButton)
hbox2.addWidget(self.exitButton)
layout = QVBoxLayout()
layout.addWidget(self.label)
layout.addLayout(hbox1)
horizontalLine = QFrame();
horizontalLine.setFrameShape(QFrame.HLine)
horizontalLine.setFrameShadow(QFrame.Sunken)
layout.addWidget(horizontalLine)
layout.addLayout(hbox2)
layout.addStretch()
self.setLayout(layout)
self.okButton.clicked.connect(self.okButtonClick)
self.exitButton.clicked.connect(self.close)

def okButtonClick(self):
choices = []
if self.perlCheck.isChecked():
choices.append('Perl')
if self.pythonCheck.isChecked():
choices.append('Python')
if self.rubyCheck.isChecked():
choices.append('Ruby')
if self.phpCheck.isChecked():
choices.append('PHP')
QMessageBox.information(self, 'Informasi', repr(choices))
Binary file not shown.
Binary file not shown.
9 changes: 9 additions & 0 deletions Modul5/DemoQCheckBox/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import sys
from PyQt5.QtWidgets import QApplication
from DemoQCheckBox import *

if __name__ == '__main__':
a = QApplication(sys.argv)
minform = MainForm()
minform.show()
a.exec()
75 changes: 75 additions & 0 deletions Modul5/DemoQLineEdit/DemoQLineEdit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import sys
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *

class MainForm(QWidget):
def __init__(self):
super().__init__()
self.setupUi()
def setupUi(self):
self.resize(400, 200)
self.move(300, 300)
self.setWindowTitle('Demo QLabel, QLineEdit, dan QPushButton')
self.label1 = QLabel()
self.label1.setText('Bilangan pertama')
self.numberEdit1 = QLineEdit()
vbox1 = QVBoxLayout()
vbox1.addWidget(self.label1)
vbox1.addWidget(self.numberEdit1)
self.label2 = QLabel()
self.label2.setText('Bilangan kedua')
self.numberEdit2 = QLineEdit()
vbox2 = QVBoxLayout()
vbox2.addWidget(self.label2)
vbox2.addWidget(self.numberEdit2)
self.label3 = QLabel()
self.label3.setText('Hasil Perhitungan')
self.resultEdit = QLineEdit()
self.resultEdit.setReadOnly(True)
vbox3 = QVBoxLayout()
vbox3.addWidget(self.label3)
vbox3.addWidget(self.resultEdit)
vbox4 = QVBoxLayout()
vbox4.addLayout(vbox1)
vbox4.addLayout(vbox2)
vbox4.addLayout(vbox3)
vbox4.addStretch()
self.addButton = QPushButton('&Tambah')
self.substractButton = QPushButton('&Kurang')
self.mulButton = QPushButton('K&ali')
self.divButton = QPushButton('&Bagi')
vbox5 = QVBoxLayout()
vbox5.addWidget(self.addButton)
vbox5.addWidget(self.substractButton)
vbox5.addWidget(self.mulButton)
vbox5.addWidget(self.divButton)
vbox5.addStretch()
layout = QHBoxLayout()
layout.addLayout(vbox4)
verticalLine = QFrame();
verticalLine.setFrameShape(QFrame.VLine)
verticalLine.setFrameShadow(QFrame.Sunken)
layout.addWidget(verticalLine)
layout.addLayout(vbox5)
self.setLayout(layout)
self.addButton.clicked.connect(self.addButtonClick)
self.substractButton.clicked.connect(self.substractButtonClick)
self.mulButton.clicked.connect(self.mulButtonClick)
self.divButton.clicked.connect(self.divButtonClick)
def calculate(self, operator):
a = float(self.numberEdit1.text())
b = float(self.numberEdit2.text())
if operator == '+': c = a + b
elif operator == '-': c = a - b
elif operator == '*': c = a * b
else: c = a / b
self.resultEdit.setText(str(c))
def addButtonClick(self):
self.calculate('+')
def substractButtonClick(self):
self.calculate('-')
def mulButtonClick(self):
self.calculate('*')
def divButtonClick(self):
self.calculate('/')
Binary file not shown.
Binary file not shown.
9 changes: 9 additions & 0 deletions Modul5/DemoQLineEdit/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import sys
from PyQt5.QtWidgets import QApplication
from DemoQLineEdit import *

if __name__ == '__main__':
a = QApplication(sys.argv)
minform = MainForm()
minform.show()
a.exec()
69 changes: 69 additions & 0 deletions Modul5/DemoQRadioButton/DemoQRadioButton.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import sys
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *

class MainForm(QWidget):
def __init__(self):
super().__init__()
self.setupUi()

def setupUi(self):
self.resize(400, 150)
self.move(300, 300)
self.setWindowTitle('Demo QRadioButton')
self.label1 = QLabel()
self.label1.setText('Bilangan pertama')
self.numberEdit1 = QLineEdit()
self.label2 = QLabel()
self.label2.setText('Bilangan kedua')
self.numberEdit2 = QLineEdit()
grid = QGridLayout()
grid.addWidget(self.label1, 0, 0)
grid.addWidget(self.numberEdit1, 0, 1)
grid.addWidget(self.label2, 1, 0)
grid.addWidget(self.numberEdit2, 1, 1)
self.addRadio = QRadioButton()
self.addRadio.setText('&Tambah')
self.addRadio.setChecked(True)
self.substractRadio = QRadioButton()
self.substractRadio.setText('&Kurang')
self.mulRadio = QRadioButton()
self.mulRadio.setText('K&ali')
self.divRadio = QRadioButton()
self.divRadio.setText('&Bagi')
hbox = QHBoxLayout()
hbox.addWidget(self.addRadio)
hbox.addWidget(self.substractRadio)
hbox.addWidget(self.mulRadio)
hbox.addWidget(self.divRadio)
self.resultLabel = QLabel('<b>Hasil penjumlahan: </b>')
self.calculateButton = QPushButton('Hitung')
layout = QVBoxLayout()
layout.addLayout(grid)
layout.addLayout(hbox)
layout.addWidget(self.resultLabel)
layout.addWidget(self.calculateButton)
layout.addStretch()
self.setLayout(layout)
self.addRadio.clicked.connect(
lambda: self.resultLabel.setText('<b>Hasil penjumlahan: </b>'))
self.substractRadio.clicked.connect(
lambda: self.resultLabel.setText('<b>Hasil pengurangan: </b>'))
self.mulRadio.clicked.connect(
lambda: self.resultLabel.setText('<b>Hasil perkalian: </b>'))
self.divRadio.clicked.connect(
lambda: self.resultLabel.setText('<b>Hasil pembagian: </b>'))
self.calculateButton.clicked.connect(self.calculateButtonClick)

def calculateButtonClick(self):
a = float(self.numberEdit1.text())
b = float(self.numberEdit2.text())
if self.addRadio.isChecked(): c = a + b
elif self.substractRadio.isChecked(): c = a - b
elif self.mulRadio.isChecked(): c = a * b
else: c = a / b
index = str(self.resultLabel.text()).index(':')
s = str(self.resultLabel.text())[:index+1]
self.resultLabel.setText('%s %.2f %s' % (s, c,
'</b>'))
Binary file not shown.
Binary file not shown.
9 changes: 9 additions & 0 deletions Modul5/DemoQRadioButton/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import sys
from PyQt5.QtWidgets import QApplication
from DemoQRadioButton import *

if __name__ == '__main__':
a = QApplication(sys.argv)
minform = MainForm()
minform.show()
a.exec()
43 changes: 43 additions & 0 deletions Modul5/DemoQTextEdit/DemoQTextEdit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import sys
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *

class MainForm(QWidget):
def __init__(self):
super().__init__()
self.setupUi()
def setupUi(self):
self.resize(400, 200)
self.move(300, 300)
self.setWindowTitle('Demo QTextEdit')
self.label1 = QLabel()
self.label1.setText('No. HP')
self.phoneEdit = QLineEdit()
vbox1 = QVBoxLayout()
vbox1.addWidget(self.label1)
vbox1.addWidget(self.phoneEdit)
self.label2 = QLabel()
self.label2.setText('Pesan')
self.messageEdit = QTextEdit()
vbox2 = QVBoxLayout()
vbox2.addWidget(self.label2)
vbox2.addWidget(self.messageEdit)
vbox3 = QVBoxLayout()
vbox3.addLayout(vbox1)
vbox3.addLayout(vbox2)
self.sendButton = QPushButton('&Kirim SMS')
self.cancelButton = QPushButton('&Batal')
hbox = QHBoxLayout()
hbox.addStretch()
hbox.addWidget(self.sendButton)
hbox.addWidget(self.cancelButton)
layout = QVBoxLayout()
layout.addLayout(vbox3)
horizontalLine = QFrame();
horizontalLine.setFrameShape(QFrame.HLine)
horizontalLine.setFrameShadow(QFrame.Sunken)
layout.addWidget(horizontalLine)
layout.addLayout(hbox)
self.setLayout(layout)
# Copyright (c) 2021.This code was written by Rohman Beny R (19104060)
Binary file not shown.
Binary file not shown.
9 changes: 9 additions & 0 deletions Modul5/DemoQTextEdit/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import sys
from PyQt5.QtWidgets import QApplication
from DemoQTextEdit import *

if __name__ == '__main__':
a = QApplication(sys.argv)
minform = MainForm()
minform.show()
a.exec()
15 changes: 15 additions & 0 deletions Modul5/GUI Minimal/MinimalForm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from PyQt5.QtWidgets import QWidget, QLabel

class MinimalForm(QWidget):
def __init__(self):
super().__init__()
self.setupUi()

def setupUi(self):
self.resize(200, 100)
self.move(300, 300)
self.setWindowTitle('GUI Minimal')

self.label = QLabel('Hello PyQt5 (Ananda Aulia)')
self.label.move(50, 40)
self.label.setParent(self)
Binary file not shown.
Binary file not shown.
9 changes: 9 additions & 0 deletions Modul5/GUI Minimal/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import sys
from PyQt5.QtWidgets import QApplication
from MinimalForm import *

if __name__ == '__main__':
a = QApplication(sys.argv)
minform = MinimalForm()
minform.show()
a.exec()
30 changes: 30 additions & 0 deletions Modul5/Signal & Slot/MainForm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from PyQt5.QtWidgets import (QWidget, QVBoxLayout,
QHBoxLayout, QLineEdit, QPushButton)

class MainForm(QWidget):
def __init__(self):
super().__init__()
self.setupUi()

def setupUi(self):
self.resize(300, 100)
self.move(300, 300)
self.setWindowTitle('Demo Signal dan Slot')

self.lineEdit = QLineEdit()
self.lineEdit.setText("Demo signal dan slot")

self.button1 = QPushButton('Bersihkan')
self.button2 = QPushButton('Tutup')

hbox = QHBoxLayout()
hbox.addWidget(self.button1)
hbox.addWidget(self.button2)

layout = QVBoxLayout()
layout.addWidget(self.lineEdit)
layout.addLayout(hbox)
self.setLayout(layout)

self.button1.clicked.connect(self.lineEdit.clear)
self.button2.clicked.connect(self.close)
Binary file not shown.
Binary file not shown.
12 changes: 12 additions & 0 deletions Modul5/Signal & Slot/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import sys
from PyQt5.QtWidgets import QApplication

from MainForm import *

if __name__ == '__main__':
a = QApplication(sys.argv)

form = MainForm()
form.show()

a.exec_()
21 changes: 21 additions & 0 deletions Modul5/Tag HTLM/TextForm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from PyQt5.QtWidgets import QWidget, QLabel

class TextForm(QWidget):
def __init__(self):
super().__init__()
self.setupUi()

def setupUi(self):
self.resize(300, 200)
self.move(300, 300)
self.setWindowTitle('Demo Tag HTML')

self.label1 = QLabel('<h1>Hello <font color=red>PyQt5</font></h1>')
self.label1.move(10, 10)
self.label1.setParent(self)

self.label2 = QLabel('''Teks ini dibuat dengan tag HTML. Teks dapat dijadikan <b>Tebal</b>,
<i>Miring</i>, dan <u>Bergaris Bawah</i>''')
self.label2.setWordWrap(True)
self.label2.move(10,50)
self.label2.setParent(self)
Binary file not shown.
Binary file not shown.
9 changes: 9 additions & 0 deletions Modul5/Tag HTLM/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import sys
from PyQt5.QtWidgets import QApplication
from TextForm import *

if __name__ == '__main__':
a = QApplication(sys.argv)
form = TextForm()
form.show()
a.exec()
Loading