Python GUI input window

Source: Internet
Author: User

In order to solve the sublime text under the Python raw_input () function can not be effective, it started a GUI window to get input ideas, a start to use Tkinter, and then think of the next or use PyQt Bar, one of the code is not where to go, and Qt is obviously more beautiful View some. Encapsulated into a module input.py:

#!/usr/bin/env python#-*-coding:utf-8-*-defGetInput (label_str=None):" "Return The Utf-8 string of text so you write in the LineEdit. Label_str:the string as the prompt of the label in the dialog." "     fromPyQt4ImportQtgui, QtcoreImportSYSifLabel_str = =None:label_str= u'The window returns the information you entered in Unicode encoding:'    Else: Label_str=Unicode (LABEL_STR)classMywindow (qtgui.qdialog): Input_str="'        def __init__(self): Qtgui.qdialog.__init__(self) self.setwindowtitle (U'GUI Input') Self.label=Qtgui.qlabel (label_str) Self.lineedit=qtgui.qlineedit () Self.ok= Qtgui.qpushbutton (U'Determine') Self.connect (Self.ok, Qtcore.signal ('clicked ()'), self.getline) Self.clean= Qtgui.qpushbutton (U'Clear') Self.connect (Self.clean, Qtcore.signal ('clicked ()'), self.cleaning) Self.cancel= Qtgui.qpushbutton (U'Cancel') Self.connect (Self.cancel, Qtcore.signal ('clicked ()'), self.quit) layout=qtgui.qgridlayout () layout.addwidget (self.label, 0, 0,1, 4) Layout.addwidget (Self.lineedit,1, 0, 1, 4) Layout.addwidget (Self.ok,2, 1, 1, 1) Layout.addwidget (Self.clean,2, 2, 1, 1) Layout.addwidget (Self.cancel,2, 3, 1, 1) self.setlayout (layout) Mywindow.input_str="'        defGetLine (self): Mywindow.input_str=Str (Self.lineEdit.text (). ToUtf8 ()) Self.close ()defCleaning (self): Self.lineEdit.setText ("')        defQuit (self): Mywindow.input_str="'Self.close () app=Qtgui.qapplication (SYS.ARGV) win=Mywindow () win.show () app.exec_ ( )returnMywindow.input_strif __name__=='__main__': Pre_str=getinput () now_str= Pre_str.decode ('Utf-8')    Printtype (PRE_STR), type (NOW_STR)PrintPre_str#Print Long (PRE_STR)    #fp = open (Now_str + '. txt ', ' wb+ ')    #fp.close ()

Use only import Input, and then use Input.getinput (' xxx ') on the line, try to support the Chinese language, only need to install PYQT4 or PYQT5 module on the line. The effect is as follows:

  

You can return a Unicode-encoded string after you enter any string in the input box, and you will no longer have to worry about how to easily enter it when debugging with Python under sublime text.

Python GUI input window

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.