Report abuse

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
from PyQt4 import Qt
import sys

#####
class Buttons(Qt.QMainWindow) :
	def __init__(self, parent = None) :
		Qt.QMainWindow.__init__(self, parent)

		self.main_widget = Qt.QWidget()
		self.setCentralWidget(self.main_widget)

		self.main_layout = Qt.QVBoxLayout()
		self.main_widget.setLayout(self.main_layout)

		self.buttons_layout = Qt.QGridLayout()
		self.main_layout.addLayout(self.buttons_layout)

		#####

		self.line_edit = Qt.QLineEdit()
		self.main_layout.addWidget(self.line_edit)

		#####

		for row in range(4) :
			for column in range(3) :
				num = row*3 + column +1
				if num == 10 : num = 0
				self.addButton(str(num), row, column)
				if num == 0 : break


	### Private ###

	def addButton(self, text, row, column) :
		button = Qt.QPushButton(text)
		self.buttons_layout.addWidget(button, row, column)
		self.connect(button, Qt.SIGNAL("clicked()"), lambda : self.line_edit.insert(text))


##########
if __name__ == "__main__" :
	app = Qt.QApplication(sys.argv)
	buttons = Buttons()
	buttons.show()
	app.exec_()