0
所以我想知道是否有人知道如何將文本從文本文件加載到框架上。 我的應用程序加載與符號匹配的鼓聲符和鼓聲音文件,並將它們加載在一起。現在我需要它加載一些文本來解釋符號,並且它應該將文本與圖像和聲音文件一起加載。WxPython加載文本
def loadImage(self, event):
self.image_file = self.images.next()
print(self.image_file)
image_file = os.path.join(IMAGE_DIR, self.image_file)
img = wx.Image(image_file, wx.BITMAP_TYPE_ANY)
width = img.GetWidth()
height = img.GetHeight()
self.imageCtrl.SetBitmap(wx.BitmapFromImage(img))
這是加載圖像的代碼。您也可以循環播放每個圖像和聲音文件。
無論如何,有沒有人有辦法添加到代碼來加載文本?
def loadImage(self, event):
self.image_file = self.images.next()
print(self.image_file)
image_file = os.path.join(IMAGE_DIR, self.image_file)
img = wx.Image(image_file, wx.BITMAP_TYPE_ANY)
width = img.GetWidth()
height = img.GetHeight()
self.imageCtrl.SetBitmap(wx.BitmapFromImage(img))
def previousPicture(self, event):
self.image_file = self.images.prev()
print(self.image_file)
image_file = os.path.join(IMAGE_DIR, self.image_file)
img = wx.Image(image_file, wx.BITMAP_TYPE_ANY)
img = img.Scale(680,143)
self.imageCtrl.SetBitmap(wx.BitmapFromImage(img))
def onPlaySound (self, event):
sound_file, ext = os.path.splitext(self.image_file)
sound_file = os.path.join(SOUND_DIR, sound_file + '.wav')
print(sound_file)
sound = wx.Sound(sound_file)
sound.Play(wx.SOUND_ASYNC)
class DIter:
#"Iterable with next and previous"
def __init__(self, ItemList):
#"Creator"
self.ItemList = ItemList
self.Index = -1
self.ListEnd = len(ItemList)
def next(self):
# """ Return the next item """
self.Index += 1
self.Index %= self.ListEnd # or to avoid wrapping self.Index = min([self.Index, self.ListEnd-1])
return self.ItemList[self.Index]
def prev(self):
#""" Return the previous item """
self.Index -= 1
if self.Index < 0:
self.Index = self.ListEnd-1 # or to avoid wrapping self.Index = 0
return self.ItemList[self.Index]
加載從在該wx.TextCtrl文本文件中的文本,我應該把它放在Def LoadImage載入圖像的地方。文本應該與符號一起加載解釋它,如果我正確地得到了我的觀點。 – Chudboy 2013-03-14 01:44:23
是的,那很好。如果LoadImage調用需要很長時間,那麼您可能最終需要將加載內容放入一個線程中。 – 2013-03-14 13:39:09
你有沒有可能給我一個我如何去做這個事情的例子?對不起,新手。 self.text_file = self.text.next() text_file = os.path.join(TEXT_DIR,self.text_file) txt = wx.TextCtrl(text_file) self.textCtrl (self.panel) 我沒有看到我可以使用的演示中的任何東西。 – Chudboy 2013-03-14 15:43:54