这里是你问什么工作的例子:
from tkinter import *
def UpdateImg ():
global img1, img2
img1 = PhotoImage(file=ImgFiles[Cur])
img2 = PhotoImage(file=ImgFiles[Cur+1])
LblImg1.configure(image = img1, text=ImgFiles[Cur])
LblImg2.configure(image = img2, text=ImgFiles[Cur+1])
def BtnNext():
global Cur
if Cur < len(ImgFiles)-2:
Cur = Cur + 2
UpdateImg ()
def BtnPrev():
global Cur
if Cur > 1:
Cur = Cur - 2
UpdateImg ()
fp = open("ImgFilesSrc.txt", "r")
ImgFiles = fp.read().split('\n')
fp.close()
Cur = 0
img1 = img2 = ''
root = Tk()
#Create the main Frame -----------------------------------------------------------------
FrmMain = Frame(root)
LblImg1 = Label(FrmMain, text = "Picture 1", anchor=W, width=120, bg="light sky blue")
LblImg2 = Label(FrmMain, text = "Picture 2", anchor=W, width=120, bg="light sky blue")
BtnPrev = Button(FrmMain, text=" < ", width=10, command=BtnPrev)
BtnNext = Button(FrmMain, text=" > ", width=10, command=BtnNext)
LblImg1.grid (row=2, rowspan = 3, column=1, columnspan=3);
LblImg2.grid (row=2, rowspan = 3, column=4, columnspan=3);
BtnPrev.grid (row=5, column=2); BtnNext.grid(row=5, column=4)
FrmMain.pack(side=TOP, fill=X)
#--------------------------------------------------------------------------
UpdateImg ()
root.mainloop()
你的问题差不多宽泛;但是,由于您似乎已经知道如何显示一张图片,因此您可以确保同时显示2个图标(只需添加其他标签即可像第一张图片一样保存图像,并且可以立即从文本文件中读取两行) –
你试过简单地复制'root.mainloop()'之前的三行来看看会发生什么? –