PYQT5 database data is displayed in the table

Source: Internet
Author: User

Database is PostgreSQL

ImportSYS fromFormImportUi_form fromPyqt5.qtImportQwidget, Qapplication,qtablewidgetitemImportPSYCOPG2classMyForm (qwidget,ui_form):def __init__(self): Super ().__init__() self.setupui (self) self.btn1.clicked.connect (self.clear) self.btn2.clicked.connect (sel F.load) self.show ()defClear (self):Pass    defload (self): conn=psycopg2.connect ("dbname=test1_data USER=JM password=123") cur=conn.cursor () Cur.execute ('SELECT * FROM table1') Rows=Cur.fetchall () row=Cur.rowcount #取得记录个数 for setting the number of rows in a table vol=Len (rows[0]) #取得字段数, sets the number of columns in the table Cur.close () conn.close () Self.table.setRowCount (Row) Self.table.setColumnCount (vol) forIinchrange (Row): forJinchRange (vol): Temp_data=Rows[i][j] #临时记录, cannot insert table data directly=Qtablewidgetitem (str (temp_data)) #转换后可插入表格 Self.table.setItem (i,j,data) app=qapplication (SYS.ARGV) W=MyForm () app.exec_ ( )

PYQT5 database data is displayed in the table

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.