to be more crystal clear, here how the things might work.
in python, to create a variable, simply we use
var1 = raw_input('your name?')
so that when using
print 'your name is ' +var1
it will print the string stored in var1.
the question is how to make that using Pyqt4? I have 3 lineEdit symbolize as name, age and gender and one textEdit to print strings from lineEdit into this textEdit. it's just like making a phonebook. is it possible? how the code will look like? i'm eagerly to know the answer..
here i provide some source to make things clearer.
this is the ui:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'phonebook.ui'
#
# Created: Sat Oct 2 15:18:52 2010
# by: PyQt4 UI code generator 4.7.2
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
class Ui_phonebook(object):
def setupUi(self, phonebook):
phonebook.setObjectName("phonebook")
phonebook.resize(240, 300)
phonebook.setMinimumSize(QtCore.QSize(240, 300))
phonebook.setMaximumSize(QtCore.QSize(240, 300))
self.label = QtGui.QLabel(phonebook)
self.label.setGeometry(QtCore.QRect(20, 30, 57, 14))
self.label.setObjectName("label")
self.label_2 = QtGui.QLabel(phonebook)
self.label_2.setGeometry(QtCore.QRect(20, 60, 57, 14))
self.label_2.setObjectName("label_2")
self.lineEdit = QtGui.QLineEdit(phonebook)
self.lineEdit.setGeometry(QtCore.QRect(110, 30, 113, 20))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtGui.QLineEdit(phonebook)
self.lineEdit_2.setGeometry(QtCore.QRect(110, 60, 113, 20))
self.lineEdit_2.setObjectName("lineEdit_2")
self.textEdit = QtGui.QTextEdit(phonebook)
self.textEdit.setGeometry(QtCore.QRect(20, 142, 201, 141))
self.textEdit.setObjectName("textEdit")
self.pushButton = QtGui.QPushButton(phonebook)
self.pushButton.setGeometry(QtCore.QRect(70, 100, 89, 23))
self.pushButton.setObjectName("pushButton")
self.retranslateUi(phonebook)
QtCore.QMetaObject.connectSlotsByName(phonebook)
def retranslateUi(self, phonebook):
phonebook.setWindowTitle(QtGui.QApplication.translate("phonebook", "Simple Phonebook", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("phonebook", "Name:", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("phonebook", "E-mail:", None, QtGui.QApplication.UnicodeUTF8))
self.lineEdit.setText(QtGui.QApplication.translate("phonebook", "lineEdit", None, QtGui.QApplication.UnicodeUTF8))
self.lineEdit_2.setText(QtGui.QApplication.translate("phonebook", "lineEdit_2", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate("phonebook", "Preview", None, QtGui.QApplication.UnicodeUTF8))
this is main source:
#! /usr/bin/env python
import sys
from PyQt4 import QtCore, QtGui
from phonebook import Ui_phonebook
class Main(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_phonebook()
self.ui.setupUi(self)
self.center()
QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL('clicked()'), self.preview)
def preview(self):
lineEdit = '"content inside lineEdit"'
lineEdit_2 = '"content inside lineEdit_2"'
self.ui.textEdit.setText('Name: ' +lineEdit +'\n\nEmail: ' +lineEdit_2)
def center(self):
screen = QtGui.QDesktopWidget().screenGeometry()
size = self.geometry()
self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
main = Main()
main.show()
sys.exit(app.exec_())