我是新手,想用python開發GUI。我的數據是一個.sgy文件,我需要顯示圖形作爲輸出。我選擇了Pyglet這樣做。這是一個正確的選擇嗎?我在第一步感到震驚,因爲我想在窗口的標籤中顯示地震數據的標題。這裏是我已經試過代碼:在pyglet中顯示標籤的動態值
import pyglet
import sys
import numpy as np #package for numerical processing
import matplotlib #package for plotting graphs
import obspy #package for reading sgy file
import pandas #package for handling csv file
from obspy.io.segy.segy import _read_segy
from obspy.core.util import get_example_file
window = pyglet.window.Window()
filename = get_example_file("/home/khyati/Downloads/FindTrappedMiners.SGY")
st = _read_segy(filename)
for i in st.traces:
label = pyglet.text.Label(i,
font_name='Times New Roman',
font_size=36,
x=window.width//2,
y=window.height//2,
anchor_x='center', anchor_y='center')
@window.event
def on_draw():
window.clear()
label.draw()
pyglet.app.run()
這裏是我遇到
TypeError Traceback (most recent call last)
<ipython-input-32-869a2d62b820> in <module>()
21 x=window.width//2,
22 y=window.height//2,
---> 23 anchor_x='center', anchor_y='center')
24
25
/home/khyati/anaconda2/lib/python2.7/site-packages/pyglet-1.2.4-py2.7.egg/pyglet/text/__init__.py in __init__(self, text, font_name, font_size, bold, italic, color, x, y, width, height, anchor_x, anchor_y, align, multiline, dpi, batch, group)
428
429 '''
--> 430 document = decode_text(text)
431 super(Label, self).__init__(document, x, y, width, height,
432 anchor_x, anchor_y,
/home/khyati/anaconda2/lib/python2.7/site-packages/pyglet-1.2.4-py2.7.egg/pyglet/text/__init__.py in decode_text(text)
210 '''
211 decoder = get_decoder(None, 'text/plain')
--> 212 return decoder.decode(text)
213
214 class DocumentLabel(layout.TextLayout):
/home/khyati/anaconda2/lib/python2.7/site-packages/pyglet-1.2.4-py2.7.egg/pyglet/text/formats/plaintext.py in decode(self, text, location)
44 def decode(self, text, location=None):
45 document = pyglet.text.document.UnformattedDocument()
---> 46 document.insert_text(0, text)
47 return document
/home/khyati/anaconda2/lib/python2.7/site-packages/pyglet-1.2.4-py2.7.egg/pyglet/text/document.py in insert_text(self, start, text, attributes)
422
423 '''
--> 424 self._insert_text(start, text, attributes)
425 self.dispatch_event('on_insert_text', start, text)
426
/home/khyati/anaconda2/lib/python2.7/site-packages/pyglet-1.2.4-py2.7.egg/pyglet/text/document.py in _insert_text(self, start, text, attributes)
426
427 def _insert_text(self, start, text, attributes):
--> 428 self._text = u''.join((self._text[:start], text, self._text[start:]))
429 len_text = len(text)
430 for element in self._elements:
TypeError: sequence item 1: expected string or Unicode, SEGYTrace found
任何幫助,將不勝感激的錯誤。
閱讀錯誤信息:什麼是'我'?一些痕跡。什麼是痕跡?不是字符串。但標籤需要字符串作爲第一個參數。所以也許你需要'str(i)'或者它可能有'i.text'或類似的東西。 – furas