我正在用Python构建一个简单的程序来显示存储在一些文件夹中的一些图像。程序从一个文件夹转到另一个文件夹,显示一个接一个的图像,如下所示:
for x in range(len(gl)):
for y in range(tn[x]):
png = wx.Image("{}\\{}\\{}".format(username, gl[x], pnglist[tot + y]), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
delpng.append(wx.StaticBitmap(self.scrollWin, -1, png, (0, 56 * (tot + y)), (56, 56)))
tot += tn[x]
在某一点上,图像停止正确显示,重叠,然后根本不显示。
所有的图像都有56个像素的宽度和高度。我不知道是什么导致了这一切。
对于它所经过的文件夹:https://www.mediafire.com/file/l5t2uk9d2d1o7o0/GamerM3243.rar/file
至于代码:
import wx
#username = str(input("Username: "))
username = "GamerM3243"
delpng = []
def ShowImages(self, username):
gl = []
glif = [0]
pnglist = []
rpnglist = []
tn = []
fl = open("{}\\{}'s Trophies.txt".format(username, username), "r", encoding = "utf-8-sig").read().split('\n')
self.scrollWin = wx.ScrolledWindow(self, -1, size = (700, 500))
for i, n in enumerate(fl):
if ''.join(list(n)[:25]) == "Number of trophies earned":
gl.append(fl[i-1])
tn.append(int(''.join(list(n)[27:])))
glif = [i for i, n in enumerate(fl) if n in gl]
for i, n in enumerate(gl):
gl[i] = ''.join([x for x in list(n) if x != ":" and x != "?" and x != '"'])
for i, n in enumerate(glif):
i1 = n + 2
try:
i2 = glif[i + 1] - 1
except IndexError:
i2 = -1
rpnglist.append(fl[i1:i2])
for x in rpnglist:
for y in x:
if y != "" and y not in gl:
pnglist.append(y)
for i, n in enumerate(pnglist):
for x, z in enumerate(list(n)):
if z == "-" and n[x - 1] == " " and n[x + 1] == " ":
pnglist[i] = ''.join(list(n)[:x - 1])
for i, n in enumerate(pnglist):
pnglist[i] = "{}.png".format(''.join([x for x in list(n) if x != ":" and x != "?" and x != '"']))
tot = 0
for x in range(len(gl)):
for y in range(tn[x]):
png = wx.Image("{}\\{}\\{}".format(username, gl[x], pnglist[tot + y]), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
delpng.append(wx.StaticBitmap(self.scrollWin, -1, png, (0, 56 * (tot + y)), (56, 56)))
tot += tn[x]
self.scrollWin.SetScrollbars(0, 1, 1400, 56 * tot)
self.Layout()
self.Show(True)
class MainWindow(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title = title, size = (700, 500))
ShowImages(self, username)
app = wx.App(False)
frame = MainWindow(None, "{}'s Trophies".format(username))
app.MainLoop()
您只需解压缩该文件,然后将.py文件放在文件夹外。谢谢你的帮助!
https://stackoverflow.com/questions/53784016
复制相似问题