# Python 3. PyQt4
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui, QtCore
# ГРАФИКА
class Window(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.resize(400, 150) # шир / выс окна
# БЛОК РАЗМЕТКИ
self.vbox = QtGui.QVBoxLayout()
# ---
self.pole_vvod = QtGui.QLineEdit('djf j.f ndsf ndk adf')
self.vbox.addWidget(self.pole_vvod)
# ---
self.btn = QtGui.QPushButton('Пуск')
self.btn.clicked.connect(self.on_click)
self.vbox.addWidget(self.btn)
# ---
self.setLayout(self.vbox)
# ---
# ЛОГИКА
def on_click(self):
#text_1 = self.pole_vvod.text()
text = self.pole_vvod.selectedText()
#text = self.pole_vvod.setSelection(1,3)
print(text)
# КОНЕЦ
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
# Python 3. PyQt4
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui, QtCore
# ГРАФИКА
class Window(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.resize(400, 150) # шир / выс окна
# ПЕРЕМЕННЫЕ КЛАССА
#self.sel_text = ''
self.sel_text_lst = []
# БЛОК РАЗМЕТКИ
self.vbox = QtGui.QVBoxLayout()
# ---
self.pole_vvod = QtGui.QLineEdit('djf j.f ndsf ndk adf')
self.pole_vvod.selectionChanged.connect(self.tx)
self.vbox.addWidget(self.pole_vvod)
# ---
self.btn = QtGui.QPushButton('Пуск')
self.btn.clicked.connect(self.on_click)
self.vbox.addWidget(self.btn)
# ---
self.setLayout(self.vbox)
# ---
# ЛОГИКА
def tx(self):
self.sel_text = self.pole_vvod.selectedText()
#print(self.sel_text)
self.sel_text_lst.insert(0,self.sel_text)
if len(self.sel_text_lst) > 2:
self.sel_text_lst.pop(2)
def on_click(self):
#text = self.sel_text
text = self.sel_text_lst[1]
print(text)
# КОНЕЦ
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())