Python Tkinter按钮,用于浏览PNG文件的文件夹 [英] Python Tkinter button to advance through a folder of PNG files

查看:475
本文介绍了Python Tkinter按钮,用于浏览PNG文件的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我甚至不知道从哪里开始编写我的代码的这部分 - >所以几乎没有样本代码可以发布。



我已经想出了如何使用matplotlib创建PNG文件,我希望一次显示一个,然后点击TKinter按钮前进。



So I don't even know where to begin writing this part of my code --> so there is little sample code to post.

I have figured out how to create PNG files using matplotlib and I want to display them one at a time and advance through them at the click of a TKinter button.

def nextDay():
    print("Next Day")
root = Tk()
photo = PhotoImage(file = "example69.png")
label = Label(root, image=photo).grid(row=0, rowspan=25, column=0)
button4 =Button(root, text="Next Day", command=nextDay).grid(row=3, column=1, sticky=E+W)
root.mainloop()





我可以加载并显示第一个,但我真正盯着定义一个空白按钮功能(nextDay)循环并将照片变量更改为下一个PNG。我只需要更改一次并让主循环刷新吗?或者我是否需要保留一份准备好循环的PNG文件列表?我不知道后者。



任何建议都将不胜感激。



I can load and display the first one, but I'm really staring at the void when it comes to defining a button function (nextDay) that loops through and changes the photo variable to the next PNG. Do I only need to change it once and let the main loop refresh it? Or do I need to keep a list of PNG files ready to loop through? I have no idea on the latter.

Any suggestions would be greatly appreciated.

推荐答案

参见< a href =http://stackoverflow.com/questions/3207219/how-to-list-all-files-of-a-directory-in-python> http://stackoverflow.com/questions/3207219/how -to-list-all-files-of-a-directory-in-python [ ^ ]。


这篇关于Python Tkinter按钮,用于浏览PNG文件的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆