2
我試圖用pyqt繪製一張地圖,它不起作用。到目前爲止,要麼我沒有輸出,要麼出現類似Seg錯誤的錯誤。繪圖PyQt畫家
這是我現在使用的代碼:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class Example(QWidget):
def __init__(self):
super(Example, self).__init__()
self.setGeometry(0, 0, 500, 500)
self.setWindowTitle('Painel')
list_ = []
file_ = open('points.txt')
for line in file_.readlines():
l = line.replace("\n", "")
l = l.split(" ")
try:
l = [float(i) for i in l]
list_.append(l)
except: pass#possible strings
first = list_[0]
list_ = list_[1:]
self.path = QPainterPath()
self.path.moveTo(*first)
for i in list_:
self.path.lineTo(*i)
def paintEvent(self, e):
qp = QPainter()
qp.begin(self)
qp.drawPath(self.path)
qp.end()
app = QApplication(sys.argv)
ex = Example()
ex.show()
app.exec_()
[編輯]這裏是一些points.txt
-57.328 -29.972
-57.323 -29.937
-57.329 -29.895
-57.328 -29.880
-57.295 -29.832
-57.242 -29.789
-57.227 -29.780
-57.171 -29.781
-57.134 -29.771
的內容,而我使用的是Mac OS 10.6 .7 & active python 2.7.1
哦,這是代碼的其餘部分。仍然,走這條線不會使paintEvent繪製路徑。 – 2011-05-15 00:15:25
你得到的堆棧跟蹤是什麼? – 2011-05-15 00:17:02
沒有堆棧跟蹤,它簡單的根本不打印。 – 2011-05-15 00:18:18