2013-12-07 27 views
-1

我想從一個gui發送一些數據我正在致力於python。 我想要做的事是寫行(gui)到列表(python)或類似的東西...(直接到numpy數組將是最好的)...PyQt表Widget條目列表或numpy數組對象

我的GUI有一個表部件我在QtDesigner創建我有一個Python程序建立這個GUI:

from PyQt4 import QtGui, QtCore 
from Main_window import Ui_Dialog as Dlg 

class MyDia(QtGui.QDialog, Dlg): 
    def __init__(self): 
     QtGui.QDialog.__init__(self) 
     self.setupUi(self) 
... 
     self.tableWidget.cellChanged.connect(self.cellchanged) #connects a signal when 
     #value in cell should be updated 
    def cellchanged(self): 
     col=self.tableWidget.currentColumn() 
     row=self.tableWidget.currentRow()   
     text = self.tableWidget.currentItem().text() 
     list=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] 
     list[col]=text 
... 

這是我的想法 - 我想要的清單(或陣列),當用戶已經改變了小區的入口被更新/改變。我只有一行,所以它不一定是二維數組。

我需要這個,因爲我發送一個陣列到我的實際計算程序,其中「名單」是輸入:

... exec(open("./calculation.py").read()) 

... from calculator import calc 
     calc(list) 

我希望有人能幫助我與此有關。 ..

+0

如果你安裝了spyder,你可以使用'spyderlib.widgets.arrayeditor'來做到這一點。 – HYRY

+0

你真正的問題是什麼?我明白你想要做什麼,但不明白你要求幫助的具體問題...... –

回答

0

嘗試使用「numpy」數組後,我成功了 - 我更改了「cellchanged」部分 並定義了一個按鈕,用戶必須在輸入LL細胞

「tableWidget」 從Main_window進口Ui_Dialog是QtDesigner或 「...」 部分 進口從PyQt4的進口QtGui numpy的作爲NP 定義的對象的名稱,QtCore
作爲DLG

class MyDia(QtGui.QDialog, Dlg): 
    def __init__(self): 
     QtGui.QDialog.__init__(self) 
... 
     self.setupUi(self) 
self.connect(self.buttonOK, 
       QtCore.SIGNAL("clicked()"), self.onOK)# the button signal 
    def onOK(self):#event when user clicks 
     list=np.zeros((1,16)) 
     for i in range(0,16,1):    
       list[0,i]= float(self.tableWidget.item(0,i).text()) 
       #reads in the first row the User has input before 

謝謝各位傢伙!