[PyQt] Newbe question about Print() to PyQt - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [PyQt] Newbe question about Print() to PyQt (/thread-7037.html) |
Newbe question about Print() to PyQt - TimW - Dec-18-2017 I am looking to porting my python code to PyQt but I don't understand how to "Print()" to a text window. a print fragment of my code is below and it produces this simple user interface screen that I would like to see in a PyQt window instead. class Start_Up_Display(object): def __init__(self): pass def start(self): global message print("\nSWITCH STATUS REPORT") print("-------------") num = 0 while num < len(Sw)-1: screen.show_all_in_line(num) num = num +1 screen.show_all_in_line(num) num = 0 if len(message)!= 0: print("\nMessage: [%s]" % message) else: print("\nMessage: ") message = '' class Display_Switch(object): def __init__(self): pass def show_all_in_line(self, abb): print("%s %s %s %s \t@ %s" % ( Sw[int(abb)][0].ljust(3), Sw[int(abb)][3].ljust(3), chr(int(Sw[int(abb)][4])), Sw[int(abb)][1].ljust(14), Sw[int(abb)][2].ljust(41)) ) Result: [Image: MRSM.jpg] RE: Newbe question about Print() to PyQt - Larz60+ - Dec-18-2017 Please re-post code between code tags, see: BBCODE in addition, when pasting code, use shift-ctrl-v to preserve indentation. You code doesn't make sense without proper indentation Also, it's better to use output tags to show results, and not images. RE: Newbe question about Print() to PyQt - TimW - Dec-19-2017 class Start_Up_Display(object): def __init__(self): pass def start(self): global message print("\nSWITCH STATUS REPORT") print("-------------") num = 0 while num < len(Sw)-1: screen.show_all_in_line(num) num = num +1 screen.show_all_in_line(num) num = 0 if len(message)!= 0: print("\nMessage: [%s]" % message) else: print("\nMessage: ") message = '' class Display_Switch(object): def __init__(self): pass def show_all_in_line(self, abb): print("%s %s %s %s \t@ %s" % ( Sw[int(abb)][0].ljust(3), Sw[int(abb)][3].ljust(3), chr(int(Sw[int(abb)][4])), Sw[int(abb)][1].ljust(14), Sw[int(abb)][2].ljust(41)) ) "Also, it's better to use output tags" I don't know what an output tag is. RE: Newbe question about Print() to PyQt - Larz60+ - Dec-19-2017 If you look at the posting editor, there are 5 icons in a group just after the quote symbol. They are in order:
I'd answer your Qt question, I'm good with wxpython and tkinter, but not a lot of experience with Qt I know the docs are here: http://doc.qt.io/qt-5/ and I did play with Qt4 from C++, but not python Someone else will probably pick up from here. RE: Newbe question about Print() to PyQt - hbknjr - Dec-19-2017 (Dec-18-2017, 10:32 PM)TimW Wrote: I don't understand how to "Print()" to a text window. In PYQT there are different widgets each for input, output display, buttons etc. There is no print() function.{Print just works on Console} Though widgets can be used to display text on the screen. eg- There's a textBrowser widget, who's setText property can be used to display a string. textbr = QTextBrowser() textbr.setText("This string will be displayed")If you're having trouble starting with UI designing with PYQT, I recommend using QTDesigner initially. Its simple drag and drop.And then the code can be converted to python. RE: Newbe question about Print() to PyQt - Larz60+ - Dec-19-2017 In Gui Programming, you 'print' to widgets in different ways, depending on the type of widget. Almost always passed as an argument. I don't see anywhere in your code the definition of 'screen' What kind of widget is being used? There are many widgets that have text attributes, see: http://doc.qt.io/qt-5/examples-widgets.html usually to display 'text' the attribute is something like text='value', but not always, RE: Newbe question about Print() to PyQt - TimW - Dec-19-2017 (Dec-19-2017, 12:06 PM)Larz60+ Wrote: In Gui Programming, you 'print' to widgets in different ways, depending on the type of widget. I am not currently using and 'screen' it's all printed to STDOUT. That is why I asked the question, I want to move to either tkinter or PyQt but I don't understand how to post multiple lines to a 'screen' and be able to dynamically update them as things change. All the examples just show a single line of text. I am obviously missing a basic concept here. How do I pass multiple lines of text (as in a for or while loop) to a screen? RE: Newbe question about Print() to PyQt - Larz60+ - Dec-19-2017 Well, we can't make that decision for you, that's up to the designer, who is you, and depends on if the text is to be by itself, or with images, if it needs to be edited, and if so are you going to require such things a cut and paste, copy to end of line, or to end of text, etc. Does the text require a response, many responses, etc. Some thing that only requires a single response or yes/no response does well in a checkbox, whereas something that needs editing capability should be a textbox, etc. I suggest that you start by doing a tutorial. Look at the link I gave you, look for a widget that might do what you need, click on the link next to that widget, and you will get a complete example of how to construct that widget complete with code example (in C, python will be very similar) For python, see: http://zetcode.com/gui/pyqt5/ RE: Newbe question about Print() to PyQt - TimW - Dec-19-2017 Yes, I have done several tutorials on both PyQt and tkinter but neither are clear on how to put more than one line of text on the screen. For brevity sake they all say things like "self.lbl.setText(text)" but that is a single piece of text. How do I send multiple lines of formatted text to a widget? RE: Newbe question about Print() to PyQt - Larz60+ - Dec-19-2017 I have one more suggestion, and then I'm done. Take a look at nullege.com and search for sample code And I don't believe that none of the tutorials were good, especially zetcode, which has a stellar reputation. You've got to put something into it to get something out. |