所以我想知道是否有人知道如何将文本文件中的文本加载到框架上。我的应用程序加载一个 Drum Notation 和一个与 Notation 匹配的 Drum 声音文件,并将它们一起加载。现在我需要它加载一些文本来解释符号,它应该将文本与图像和声音文件一起加载。
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]