Sunday, May 1, 2022

Create a Lock Screen in Windows with PyQt6

This demo program shows how to create a lockscreen and detect any movement within the Windows OS. 

The Output: 

 


The Code: 

 


  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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import sys
from PyQt6.QtCore import *
from PyQt6.QtGui import *
from PyQt6.QtWidgets import *
import time
from ctypes import *
x_idle = 0
x_idle_toggle = 0
start_tmr = 0
class XScreenSaverInfo(Structure):
    _fields_ = [('window', c_long),
                ('state', c_int),
                ('kind', c_int),
                ('til_or_since',c_ulong),
                ('idle', c_ulong),
                ('eventMask', c_ulong)]

class LASTINPUTINFO(Structure):
    _fields_ = [
        ('cbSize', c_uint),
        ('dwTime', c_uint),
    ]
def get_idle_duration():
    lastInputInfo = LASTINPUTINFO()
    lastInputInfo.cbSize = sizeof(lastInputInfo)
    windll.user32.GetLastInputInfo(byref(lastInputInfo))
    millis = windll.kernel32.GetTickCount() - lastInputInfo.dwTime
    return millis / 1000.0

class inputdialogdemo(QMainWindow):
    def __init__(self, parent = None):
      super(inputdialogdemo, self).__init__(parent)
      fnt = QFont('Open Sans', 16, QFont.Weight.Bold)
      self.lblIdle = QLabel('Idle Time', self)
      self.lblIdle.setFont(fnt)
      self.lblIdle.setGeometry(20, 40, 300, 30)
      pb3 = QPushButton('Show Lockscreen ', self)
      pb3.setGeometry(50, 100, 130, 30)
      
      pb3.clicked.connect(self.onClick_pb3)
      pb5 = QPushButton('Reset Idle', self)
      pb5.setGeometry(200, 100, 130, 30)
      
      pb5.clicked.connect(self.onClick_pb5)
      self.timer = QTimer(self)
      self.timer.timeout.connect(self.showTime)
      self.timer.start(1000) # update every second
      
      self.move(100, 200)
      self.setFixedSize(400, 300)
      self.setWindowTitle('Post 30')
    def exec_idel(self):
      global x_idle_toggle
      global x_idle
      global start_tmr
        
      while x_idle_toggle ==1:
        GetLastInputInfo = int(get_idle_duration())
        print(GetLastInputInfo)
        if GetLastInputInfo == 1:
          start_tmr = 1
          x_idle = 0
          x_idle_toggle = 0
          #self.timer.stop()
          self.buildExamplePopup()
          break
        if GetLastInputInfo == 1:
          start_tmr = 1
          x_idle = 0
          x_idle_toggle = 0
          #self.timer.stop()
          self.buildExamplePopup()
          break
        time.sleep(1)      
    def start_timer(self):
        global x_idle
        x_idle = 0 
        #self.timer = QTimer(self)
        #self.timer.timeout.connect(self.showTime)
        self.lblIdle.setText("Idle Time: " + str(x_idle))
        self.timer.start(1000) # update every second
        
        
    def mousePressEvent(self, QMouseEvent):
        global x_idle
        x_idle = 0     
    def showTime(self):
        global x_idle
        global x_idle_toggle
        global start_tmr
        self.lblIdle.setText("Idle Time: " + str(x_idle))
        if start_tmr == 0:
           x_idle = x_idle + 1
        if x_idle > 10 and x_idle_toggle == 0:
           x_idle_toggle = 1
           x_idle = 0
           self.exec_idel()
    def onClick_pb5(self):
        global x_idle
        x_idle = 0 
        self.lblIdle.setText("Idle Time: " + str(x_idle))
        self.timer.start(1000)
    def onClick_pb3(self):
        global x_idle
        global start_tmr
        start_tmr = 1
        x_idle = 0
        #self.timer.stop()
        self.buildExamplePopup()
    def buildExamplePopup(self):
        name = 'Lock Screen'
        self.exPopup = examplePopup(name)
        
        #self.exPopup.setGeometry(self.pos().x()+50, self.pos().y()+75, 300, 225)
        self.exPopup.move(self.pos().x()+50, self.pos().y()+75)
        self.exPopup.setFixedSize(300, 225)
        self.exPopup.show()
        
class examplePopup(QMainWindow):
    def __init__(self, name):
        super().__init__()
        
        self.name = name
        self.setWindowFlags(Qt.WindowType.Window | Qt.WindowType.CustomizeWindowHint | Qt.WindowType.WindowStaysOnTopHint)
        self.initUI()

    def initUI(self):
        fnt = QFont('Open Sans', 16, QFont.Weight.Bold)
        lblName = QLabel(self.name, self)
        lblName.setFont(fnt)
        lblName.setGeometry(50, 40, 200, 30)
        lblpwd =  QLabel('Password', self)
        lblpwd.setStyleSheet('QLabel {background-color: transparent; color: black;}')
        lblpwd.setGeometry(25, 115, 100, 30) 
        txtpwd = QLineEdit('', self) 

        txtpwd.setPlaceholderText("Enter Password Here")
        txtpwd.setGeometry(110, 115, 150, 30) 
        txtpwd.setEchoMode(QLineEdit.EchoMode.Password)
        
        pb4 = QPushButton('Ok', self)
        pb4.move(90, 175)
        
        pb4.clicked.connect(self.onClick_pb4)
        
    def mousePressEvent(self, QMouseEvent):
        global x_idle
        x_idle = 0 
    def onClick_pb4(self):
        global x_idle
        global start_tmr 

        start_tmr = 0
        
        x_idle = 0 
        
        self.close()
        
        
        	
def main(): 
   app = QApplication(sys.argv)
   ex = inputdialogdemo()
   ex.show()
   sys.exit(app.exec())
	
if __name__ == '__main__':
   main()

Friday, April 29, 2022

Display CPU and Virtual Memory in Realtime with PyQt6 and Matplotlib

 This demo program shows how to display in real time the CPU usage and Virtual Memory Usage in % using a donut shape graph from matplotlib.

The output:



The Code:

  1
 
159
import sys
import psutil
import os
from PyQt6.QtWidgets import QApplication, QWidget, QLabel
from PyQt6.QtGui import QFont
from PyQt6.QtCore import QTimer, QTime, Qt

from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
from matplotlib.figure import Figure
from matplotlib.patches import Circle

i = 5
d = 95
class MplCanvas(FigureCanvasQTAgg):
    def __init__(self, parent=None, width=5, height=4, dpi=100):
        super(MplCanvas, self).__init__(Figure(figsize=(width, height), dpi=dpi))
        self.axes = self.figure.add_subplot(111)
        self.setParent(parent)


class MplWidget(QWidget):
    def __init__(self, parent=None):
        global i
        global d
        QWidget.__init__(self, parent)

        self.canvas = MplCanvas(self)
        self.canvas1 = MplCanvas(self)
        d = 100 - i
        labels = ["a", "b"]
        data = [d, i]
        
        #colors = ["#f2f2f2", "#ff9999"]
        colors = ["#f2f2f2", "blue"]

        self.canvas.axes.pie(
                data,
                colors=colors,
                startangle=90,
               pctdistance=0.85
        )
        
        self.canvas1.axes.pie(
                data,
                colors=colors,
                startangle=90,
               pctdistance=0.85
        )

        centre_circle = Circle((0, 0), 0.70, fc="white")
        self.canvas.axes.add_artist(centre_circle)
        self.canvas.axes.axis("equal")
        self.canvas.figure.tight_layout()
        self.canvas.setGeometry(75,75,100,100)
        self.canvas.draw()
        centre_circle1 = Circle((0, 0), 0.70, fc="white")
        self.canvas1.axes.add_artist(centre_circle1)
        self.canvas1.axes.axis("equal")
        self.canvas1.figure.tight_layout()
        self.canvas1.setGeometry(200,75,100,100)
        self.canvas1.draw()
        
        fnt = QFont('Open Sans', 11, QFont.Weight.Bold)
        fnt1 = QFont('Open Sans', 9)
        self.lbl = QLabel(self)
        self.lbl.setAlignment(Qt.AlignmentFlag.AlignCenter)
        self.lbl.setFont(fnt)
        
        self.lbl.setGeometry(78,110,100, 30)
        
        self.lbl1 = QLabel(self)
        self.lbl1.setAlignment(Qt.AlignmentFlag.AlignCenter)
        self.lbl1.setFont(fnt1)
        
        self.lbl1.setGeometry(78,50,100, 30)
        self.lbl1.setText('CPU Usage')
        
        self.lbl2 = QLabel(self)
        self.lbl2.setAlignment(Qt.AlignmentFlag.AlignCenter)
        self.lbl2.setFont(fnt)
        
        self.lbl2.setGeometry(200,110,100, 30)
        
        self.lbl3 = QLabel(self)
        self.lbl3.setAlignment(Qt.AlignmentFlag.AlignCenter)
        self.lbl3.setFont(fnt1)
        
        self.lbl3.setGeometry(200,50,100, 30)
        self.lbl3.setText('Virtual Mem Usage')
        
        
        timer = QTimer(self)
        timer.timeout.connect(self.showTime)
        timer.start(10000) # update every second
        self.setGeometry(50,75,400,250)
        self.setWindowTitle('Post 29')
        self.showTime()
    def showTime(self):
        global i
        global d
        #currentTime = QTime.currentTime()
        i = psutil.cpu_percent()
        #displayTxt = currentTime.toString('hh:mm:ss')
        self.lbl.setText(str(i) + '%')
        
            
        d = 100 - i
        labels = ["a", "b"]
        data = [d, i]
        
        colors = ["#f2f2f2", "blue"]

        self.canvas.axes.pie(
                data,
                colors=colors,
                startangle=90,
               pctdistance=1
        )
        colors = ["#f2f2f2", "green"]
        centre_circle = Circle((0, 0), 0.85, fc="white")
        self.canvas.axes.add_artist(centre_circle)
        self.canvas.axes.axis("equal")
        self.canvas.figure.tight_layout()
        self.canvas.setGeometry(75,75,100,100)
        self.canvas.draw()
        i = psutil.virtual_memory().available * 100 / psutil.virtual_memory().total
        self.lbl2.setText(str(round(i,2)) + '%')
        d = 100 - i
        data = [d, i]
        self.canvas1.axes.pie(
                data,
                colors=colors,
                startangle=90,
               pctdistance=1
        )
        
        centre_circle1 = Circle((0, 0), 0.85, fc="white")
        self.canvas1.axes.add_artist(centre_circle1)
        self.canvas1.axes.axis("equal")
        self.canvas1.figure.tight_layout()
        self.canvas1.setGeometry(200,75,100,100)
        self.canvas1.draw()
            #self.update
       
                    
        i = i + 5
        

def main():
    app = QApplication(sys.argv)

    widget = MplWidget()
    widget.show()

    sys.exit(app.exec())


if __name__ == "__main__":
    main()


Thursday, April 28, 2022

Display Map with Markers and Polygons with Folium and PyQt6

This demo program show how to create a folium map and attach it to qwbengineview to place is anywhere on a window and update the map with a press of a button.


The Output:



The code:

 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
import sys
import io
import folium 
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QApplication, QPushButton
from PyQt5.QtWebEngineWidgets import QWebEngineView # pip install PyQtWebEngine

class Window(QMainWindow):

    def __init__(self):
        super(Window, self).__init__()      
         
        self.initUI()

    def initUI(self):
         
        self.pb1 = QPushButton('Update', self)
        self.pb1.setGeometry(340, 330, 100, 30)       
        self.pb1.clicked.connect(self.onClick_pb2)        
        
        coordinate = (15.872172863923, 120.39238696289)
        m = folium.Map(
        	#tiles='Stamen Terrain',
        	#tiles='cartodbpositron',
            tiles='Stamen Toner',
            zoom_start=13,
        	location=coordinate
        )
        folium.Rectangle([(15.882172863923, 120.41238696289), (15.862172863923, 120.38238696289)],
                    color="blue",
                    weight=1,
                    fill=True,
                    fill_color="blue",
                    fill_opacity=0.1).add_to(m)
        folium.Marker(location=[15.872172863923, 120.39238696289],popup='Basista',tooltip='Click here to see Popup',icon=folium.Icon(color='purple',prefix='fa',icon='anchor')).add_to(m)
        # save map data to data object
        data = io.BytesIO()
        m.save(data, close_file=False)

        self.webView = QWebEngineView(self)
        self.webView.setHtml(data.getvalue().decode())
        self.webView.setGeometry(20,20, 420,280)
        self.setGeometry(25, 45, 450, 370)
        self.setWindowTitle('Post 28')
        self.show()
        
    def onClick_pb2(self):
        coordinate1 = (14.5409, 121.0503)
        m = folium.Map(
        	#tiles='Stamen Terrain',
        	tiles='cartodbpositron',
            zoom_start=18,
        	location=coordinate1
        )
        folium.Circle(location=[14.5409, 121.0503], popup='BGC', fill_color='green', fill_opacity=0.1, radius=50, weight=0, color="green").add_to(m)
        folium.Marker(location=[14.5409, 121.0503],popup='BGC',tooltip='Click here to see Popup').add_to(m)
        data = io.BytesIO()
        m.save(data, close_file=False)
        
        self.webView.setHtml(data.getvalue().decode())                    

def main():

    app = QApplication(sys.argv)
    ex = Window()
    ex.show()
    sys.exit(app.exec())


if __name__ == '__main__':
    main()

Wednesday, April 27, 2022

Create Volume Control Dial, List box, Toggle Button, Slider and a Spin Box in PyQt6

This demo program shows how to create Volume Control Dial, List box, Toggle Button, Slider and a Spin Box and place on specific location in a window.


The output:



The code:

  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
from PyQt6.QtWidgets import (QWidget, QSlider, QListWidget, QSpinBox, QPushButton, QDial,
        QLabel, QApplication)
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QPixmap
import sys

on_load = 0
class Example(QWidget):

    def __init__(self):
        super().__init__()

        self.initUI()


    def initUI(self):
        self.redb = QPushButton('Horizontal', self)
        self.redb.setCheckable(True)
        self.redb.setGeometry(20, 5, 80, 20)
        self.redb.clicked[bool].connect(self.setColor)
        
        self.sld = QSlider(Qt.Orientation.Horizontal, self)
        self.sld.setFocusPolicy(Qt.FocusPolicy.NoFocus)
        self.sld.setGeometry(30, 45, 200, 30)
        self.sld.valueChanged[int].connect(self.changeValue)
        self.sld.setSingleStep(2)
        
        self.sld1 = QSlider(Qt.Orientation.Vertical, self)
        self.sld1.setFocusPolicy(Qt.FocusPolicy.NoFocus)
        self.sld1.setGeometry(255, 45, 30, 200)
        self.sld1.valueChanged[int].connect(self.changeValue1)
        
        self.sld1.setSingleStep(2)
        
        self.label = QLabel(self)       
        self.label.setGeometry(30, 20, 200, 30)
        self.label.setAlignment(Qt.AlignmentFlag.AlignCenter)
        
        
        self.widget = QListWidget(self)
        self.widget.addItems(["One", "Two", "Three"])
        self.widget.setGeometry(30, 95, 75, 120)
        self.llabel = QLabel(self)       
        self.llabel.setGeometry(100, 115, 75, 30)
        self.llabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
        self.label.setText('slide the bar')
        self.llabel.setText('click an item')
        #self.widget.currentItemChanged.connect(self.index_changed)
        self.widget.currentTextChanged.connect(self.text_changed)
        
        self.widget1 = QSpinBox(self)
        self.widget1.setMinimum(-10)
        self.widget1.setMaximum(10)
        self.widget1.setPrefix("$")
        self.widget1.setSuffix("c")
        self.widget1.setGeometry(30, 235, 75, 30)
        self.slabel = QLabel(self)       
        self.slabel.setGeometry(115, 235, 75, 30)
        self.slabel.setText('click to change the value')
        
        self.dialer = QDial(self)
        self.dialer.setRange(0, 100)
        self.dialer.setSingleStep(0.5)
        self.dialer.valueChanged.connect(self.value_changed_dialer)
        self.dialer.setNotchesVisible(True)
        self.dialer.move(110,300)
        self.dslabel = QLabel(self)       
        self.dslabel.setGeometry(125, 400, 75, 30)
        self.dslabel.setText('rotate the dial')
        self.dslabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
        
        self.widget1.textChanged.connect(self.value_changed_str)
        self.setGeometry(200, 100, 350, 430)
        self.setWindowTitle('Post 27')
        self.show()
    def value_changed_dialer(self, i):
        self.dslabel.setText(str(i))
        
    def setColor(self, pressed):
        if pressed:
            self.redb.setText("Vertical")
            
        else:
            self.redb.setText("Horizontal")
            
    
        
    def value_changed_str(self, s):
        self.slabel.setText(s)
    #def index_changed(self, i): # Not an index, i is a QListItem
    #    print(i.text())
    #    self.llabel.setText(i.text())
    def text_changed(self, s): # s is a str
        global on_load
        print(s)
        if on_load == 1:
          self.llabel.setText(s)
        on_load = 1
    def changeValue(self, value):

        self.label.setText(str(value))
        self.sld1.setValue(value)
        self.sld1.repaint()
    def changeValue1(self, value):

        self.label.setText(str(value))
        self.sld.setValue(value)
        self.sld.repaint()        

def main():
    
    app = QApplication(sys.argv)
    ex = Example()
    
    sys.exit(app.exec())
   

if __name__ == '__main__':
    main()
    on_load = 1

Checkbox, Radiobutton and ComboBox in PyQt6

This demo program shows how to create checkbox, radiobutton and combobox and place them at certain location in the window.

The output:



The Code:


  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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import sys
import os
from PyQt6.QtWidgets import QMainWindow, QApplication,  QWidget, QComboBox, QLineEdit, QLabel, QRadioButton, QButtonGroup, QCheckBox, QHBoxLayout, QVBoxLayout
from PyQt6 import QtCore, QtGui

class Window(QMainWindow):

    def __init__(self):
        super(Window, self).__init__()
        
 
        
        self.initUI()

    def initUI(self):
        self.setCentralWidget(QWidget(self))
        self.line_edit = QLineEdit(self)
        self.line_edit.setGeometry(25, 25, 150, 40)
        self.line_edit.setFocusPolicy(QtCore.Qt.FocusPolicy.StrongFocus)
        self.line_edit.setFocus()
        self.line_edit.setPlaceholderText('Enter Text Here')
        self.linelabel = QLabel('Entered Text Here', self)
        self.linelabel.setGeometry(25, 35, 180, 120)
        self.linelabel.setWordWrap(True)
        
        self.langs ={'c':0, 'cpp':0, 'java':0, 'python':0}
        
        self.checkBox_c = QCheckBox(self)
        self.checkBox_c.setGeometry(25, 155, 81, 20)
        self.checkBox_c.stateChanged.connect(self.checkedc)
          
        self.checkBox_cpp = QCheckBox(self)
        self.checkBox_cpp.setGeometry(116, 155, 81, 20)
        self.checkBox_cpp.stateChanged.connect(self.checkedcpp)
          
        self.checkBox_java = QCheckBox(self)
        self.checkBox_java.setGeometry(207, 155, 81, 20)
        self.checkBox_java.stateChanged.connect(self.checkedjava)
          
        self.checkBox_py = QCheckBox(self)
        self.checkBox_py.setGeometry(298, 155, 81, 20)
        self.checkBox_py.stateChanged.connect(self.checkedpy)
        
        self.checkBox_c.setText("C")
        self.checkBox_cpp.setText( "C++")
        self.checkBox_java.setText("Java")
        self.checkBox_py.setText("Python")
        
        self.clabel1 = QLabel(self)
        self.clabel1.setGeometry(25, 130, 200, 20)
        self.clabel1.setText("Select the Language you know:")
        
        
        
        self.radioButton_male = QRadioButton(self) 
        self.radioButton_male.setGeometry(45, 200, 81, 20)
        self.radioButton_male.toggled.connect(self.maleselected)
                
        self.radioButton_female = QRadioButton(self) 
        self.radioButton_female.setGeometry(45, 225, 81, 20)        
        self.radioButton_female.toggled.connect(self.femaleselected)
        
        self.radioButton_small = QRadioButton(self) 
        self.radioButton_small.setGeometry(215, 200, 81, 20)
        self.radioButton_small.toggled.connect(self.smallselected)
        self.radioButton_medium = QRadioButton(self)
        self.radioButton_medium.setGeometry(215, 225, 81, 20)        
        self.radioButton_medium.toggled.connect(self.mediumselected)         
        self.radioButton_large = QRadioButton(self)  
        self.radioButton_large.setGeometry(215, 245, 81, 20)
        self.radioButton_large.toggled.connect(self.largeselected)
        
        self.label = QLabel(self)
        self.label.setGeometry(45, 250, 150, 20)
        self.slabel = QLabel(self)
        self.slabel.setGeometry(215, 270, 150, 20)
        self.radioButton_male.setText("Male")
        self.label.setText("Select your gender:")
        self.radioButton_female.setText("Female")
        
        self.radioButton_small.setText("Small")
        self.radioButton_medium.setText("Medium")
        self.slabel.setText("Select your size:")
        self.radioButton_large.setText("Large")
        gender_group=QButtonGroup(self)
        size_group=QButtonGroup(self)
                      
        
        
        gender_group.addButton(self.radioButton_male)
        gender_group.addButton(self.radioButton_female)
        
        size_group.addButton(self.radioButton_small)
        size_group.addButton(self.radioButton_medium)
        size_group.addButton(self.radioButton_large)
        
        
        self.combo_box = QComboBox(self)
        self.combo_box.setGeometry(125, 315, 120, 20)
        self.combo_box.addItem("Black")
        self.combo_box.addItem("Blue")
        self.combo_box.addItem("Brown")
        self.combo_box.addItem("Red")
        
        self.combo_box_label = QLabel(self)
        self.combo_box_label.setGeometry(25, 315, 100, 20)
        self.combo_box_label.setText("Select color:")
        self.combo_box_label_s = QLabel(self)
        self.combo_box_label_s.setGeometry(255, 315, 100, 20)
        self.line_edit.returnPressed.connect(lambda: self.do_action())
        self.combo_box.activated.connect(self.on_combobox_changed)
        self.setGeometry(25, 45, 400, 360)
        self.setWindowTitle('Post 26')
        self.show()
        
    def on_combobox_changed(self, value):
        print("combobox changed", value)
        self.combo_box_label_s.setText(self.combo_box.currentText())
    def mouseMoveEvent(self, e):

        x = int(e.position().x())
        y = int(e.position().y())

        #text = f'x: {x},  y: {y}'
        #self.linelabel.setText(text)
        self.line_edit.setFocus()
            
    def maleselected(self, selected):
        if selected:
            self.label.setText("You are male")
             
    def femaleselected(self, selected):
        if selected:
            self.label.setText("You are female")
            
    def smallselected(self, selected):
        if selected:
            self.slabel.setText("Your size is small")
             
    def mediumselected(self, selected):
        if selected:
            self.slabel.setText("Your size is medium")
    def largeselected(self, selected):
        if selected:
            self.slabel.setText("Your size is large")       
            
    def checkedc(self, checked):
        if checked:
            self.langs['c']= 1
        else:
            self.langs['c']= 0
        self.show1()
  
    def checkedcpp(self, checked):
        if checked:
            self.langs['cpp']= 1
        else:
            self.langs['cpp']= 0    
        self.show1()
              
    def checkedjava(self, checked):
        if checked:
            self.langs['java']= 1
        else:
            self.langs['java']= 0
        self.show1()
              
    def checkedpy(self, checked):
        if checked:
            self.langs['python']= 1
        else:
            self.langs['python']= 0
        self.show1() 
    
    def show1(self):
        checkedlangs =', '.join([key for key in self.langs.keys()
                                         if self.langs[key]== 1]) 
          
        # Updates message having list of all selected languages. 
        self.clabel1.setText("You know "+checkedlangs)
    def do_action(self):

        value = self.line_edit.text()
        self.linelabel.setText(value)
       
 
        


def main():

    app = QApplication(sys.argv)
    ex = Window()
    ex.show()
    sys.exit(app.exec())


if __name__ == '__main__':
    main()