Issue
I'm trying to put functions to my UI that has lineEdit
where i could type and a SEND button which can then forward the text to the textBrowser
to display, but i'm getting the error.
AttributeError: 'QTextBrowser' object has no attribute 'get'
from PyQt4 import QtGui
import sys
import design
class ExampleApp(QtGui.QDialog, design.Ui_Dialog):
def __init__(self):
super(self.__class__, self).__init__()
self.setupUi(self)
self.sendButton.clicked.connect(self.send_message)
def send_message(self):
text_contents = self.lineEdit.get()
self.textBrowser.insert(text_contents)
I may have used things wrong, correct me where i did mistakes.
design.ui here:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>441</width>
<height>531</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>441</width>
<height>531</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>441</width>
<height>531</height>
</size>
</property>
<property name="windowTitle">
<string>Chatbot</string>
</property>
<property name="windowIcon">
<iconset>
<normaloff>../python gui/chatbot.png</normaloff>../python gui/chatbot.png</iconset>
</property>
<property name="accessibleName">
<string/>
</property>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>340</x>
<y>450</y>
<width>91</width>
<height>81</height>
</rect>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset>
<normaloff>../python gui/mic.png</normaloff>../python gui/mic.png</iconset>
</property>
<property name="iconSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRepeat">
<bool>false</bool>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit">
<property name="geometry">
<rect>
<x>10</x>
<y>450</y>
<width>221</width>
<height>81</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
</widget>
<widget class="QTextBrowser" name="textBrowser">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>441</width>
<height>441</height>
</rect>
</property>
<property name="font">
<font>
<family>MS Shell Dlg 2</family>
<pointsize>16</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
</widget>
<widget class="QPushButton" name="sendButton">
<property name="geometry">
<rect>
<x>240</x>
<y>450</y>
<width>91</width>
<height>81</height>
</rect>
</property>
<property name="font">
<font>
<family>Lucida Console</family>
<pointsize>16</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="statusTip">
<string/>
</property>
<property name="whatsThis">
<string/>
</property>
<property name="text">
<string>SEND</string>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
Solution
lineEdit is a QLineEdit so if you need to get the text you must use the text()
method, and textBrowser is a QTextBrowser and to add text you must use append()
def send_message(self):
text_contents = self.lineEdit.text()
self.textBrowser.append(text_contents)
Answered By - eyllanesc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.