FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonprogramming/pyqt5_lesson_11.py at pythonprogramming · ppattar/pythonprogramming · GitHub
ppattar
/
pythonprogramming
Public
forked from
kenwaldek/pythonprogramming
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonprogramming
/
pyqt5_lesson_11.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
129 lines (97 loc) · 3.96 KB
Breadcrumbs
pythonprogramming
/
pyqt5_lesson_11.py
Copy path
File metadata and controls
129 lines (97 loc) · 3.96 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#! /usr/bin/env python3
# -*- coding:utf-8 -*-
###############################################################
# kenwaldek MIT-license
# Title: PyQt5 lesson 11 Version: 1.0
# Date: 09-01-17 Language: python3
# Description: pyqt5 gui and font widget
# pythonprogramming.net from PyQt4 to PyQt5
###############################################################
# do something
import
sys
from
PyQt5
.
QtCore
import
QCoreApplication
,
Qt
from
PyQt5
.
QtGui
import
QIcon
from
PyQt5
.
QtWidgets
import
QApplication
,
QWidget
,
QMainWindow
,
QPushButton
,
QAction
,
QMessageBox
from
PyQt5
.
QtWidgets
import
QCheckBox
,
QProgressBar
,
QComboBox
,
QLabel
,
QStyleFactory
from
PyQt5
.
QtWidgets
import
QFontDialog
class
window
(
QMainWindow
):
def
__init__
(
self
):
super
(
window
,
self
).
__init__
()
self
.
setGeometry
(
50
,
50
,
500
,
300
)
self
.
setWindowTitle
(
'pyqt5 Tut'
)
# self.setWindowIcon(QIcon('pic.png'))
extractAction
=
QAction
(
'&Get to the choppah'
,
self
)
extractAction
.
setShortcut
(
'Ctrl+Q'
)
extractAction
.
setStatusTip
(
'leave the app'
)
extractAction
.
triggered
.
connect
(
self
.
close_application
)
self
.
statusBar
()
mainMenu
=
self
.
menuBar
()
fileMenu
=
mainMenu
.
addMenu
(
'&File'
)
fileMenu
.
addAction
(
extractAction
)
extractAction
=
QAction
(
QIcon
(
'pic.png'
),
'flee the scene'
,
self
)
extractAction
.
triggered
.
connect
(
self
.
close_application
)
self
.
toolBar
=
self
.
addToolBar
(
'extraction'
)
self
.
toolBar
.
addAction
(
extractAction
)
fontChoice
=
QAction
(
'Font'
,
self
)
fontChoice
.
triggered
.
connect
(
self
.
font_choice
)
# self.toolBar = self.addToolBar('Font')
self
.
toolBar
.
addAction
(
fontChoice
)
self
.
home
()
def
font_choice
(
self
):
font
,
valid
=
QFontDialog
.
getFont
()
if
valid
:
self
.
styleChoice
.
setFont
(
font
)
def
home
(
self
):
btn
=
QPushButton
(
'quit'
,
self
)
btn
.
clicked
.
connect
(
self
.
close_application
)
btn
.
resize
(
btn
.
sizeHint
())
btn
.
move
(
0
,
100
)
checkBox
=
QCheckBox
(
'Enlarge window'
,
self
)
# checkBox.toggle() # if you want to be checked in in the begin
checkBox
.
move
(
0
,
50
)
checkBox
.
stateChanged
.
connect
(
self
.
enlarge_window
)
self
.
progress
=
QProgressBar
(
self
)
self
.
progress
.
setGeometry
(
200
,
80
,
250
,
20
)
self
.
btn
=
QPushButton
(
'download'
,
self
)
self
.
btn
.
move
(
200
,
120
)
self
.
btn
.
clicked
.
connect
(
self
.
download
)
self
.
styleChoice
=
QLabel
(
'Windows'
,
self
)
comboBox
=
QComboBox
(
self
)
comboBox
.
addItem
(
'motif'
)
comboBox
.
addItem
(
'Windows'
)
comboBox
.
addItem
(
'cde'
)
comboBox
.
addItem
(
'Plastique'
)
comboBox
.
addItem
(
'Cleanlooks'
)
comboBox
.
addItem
(
'windowsvista'
)
comboBox
.
move
(
25
,
250
)
self
.
styleChoice
.
move
(
25
,
150
)
comboBox
.
activated
[
str
].
connect
(
self
.
style_choice
)
self
.
show
()
def
style_choice
(
self
,
text
):
self
.
styleChoice
.
setText
(
text
)
QApplication
.
setStyle
(
QStyleFactory
.
create
(
text
))
def
download
(
self
):
self
.
completed
=
0
while
self
.
completed
<
100
:
self
.
completed
+=
0.0001
self
.
progress
.
setValue
(
self
.
completed
)
def
enlarge_window
(
self
,
state
):
if
state
==
Qt
.
Checked
:
self
.
setGeometry
(
50
,
50
,
1000
,
600
)
else
:
self
.
setGeometry
(
50
,
50
,
500
,
300
)
def
close_application
(
self
):
choice
=
QMessageBox
.
question
(
self
,
'Message'
,
"Are you sure to quit?"
,
QMessageBox
.
Yes
|
QMessageBox
.
No
,
QMessageBox
.
No
)
if
choice
==
QMessageBox
.
Yes
:
print
(
'quit application'
)
sys
.
exit
()
else
:
pass
if
__name__
==
"__main__"
:
# had to add this otherwise app crashed
def
run
():
app
=
QApplication
(
sys
.
argv
)
Gui
=
window
()
sys
.
exit
(
app
.
exec_
())
run
()
Back
|
FazBrowse Home
|
New Git URL