亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

python tkiner實現 一個小小的圖片翻頁功能的示例代碼

瀏覽:3日期:2022-07-19 16:12:43

具體代碼如下所示:

import tkinter as tkimport tkinter.messageboximport copyimport os,sysdef get_picture(dirs):’’’獲得所有圖片’’’ picture_list = [] for dir,dir_abs,files in os.walk(dirs): for file in files: if file.endswith(’.gif’):picture_list.append(os.path.join(dir,file)) return picture_listclass Window: button_list = [] object_list = [] pictures = get_picture(picture_path) file = pictures[0] is_show = True index = 0 image_file = ’’ def __init__(self): ’’’創建窗口和frame’’’ self.window = tk.Tk() self.window.title(’my window’) self.window.geometry(’600x600’) self.frame = tk.Frame(self.window) self.frame.pack() self.frame_l = tk.Frame(self.frame) self.frame_r = tk.Frame(self.frame) self.frame_l.pack(side=’left’) self.frame_r.pack(side=’right’) self.frame_ll = tk.Frame(self.frame_r) self.frame_rr = tk.Frame(self.frame_r) self.frame_ll.pack(side=’left’) self.frame_rr.pack(side=’right’) def next_picture(self): ’’’下一張圖片’’’ self.index = self.pictures.index(self.file) self.index += 1 if self.index < len(self.pictures): self.checkout_button() self.file = self.pictures[self.index] self.create_canvas(self.file) else: self.index = len(self.pictures) - 1 tkinter.messagebox.showinfo(’提示’, ’已近是最后一張了’) def checkout_button(self): ’’’判斷列表中是否只有button對象’’’ object_list_copy = copy.copy(self.object_list) for ob in self.object_list: if ob in self.button_list:pass else:b = object_list_copy.pop(self.object_list.index(ob))b.destroy() self.object_list = object_list_copy def pre_picture(self): ’’’上一頁’’’ self.index = self.pictures.index(self.file) self.index -= 1 if self.index >= 0: self.checkout_button() self.file = self.pictures[self.index] self.create_canvas(self.file) else: self.index = 0 tkinter.messagebox.showinfo(’提示’, ’已經是第一張了’) def show_picture(self): ’’’展示圖片和翻頁按鈕’’’ self.file = self.pictures[0] if self.is_show: self.is_show = False self.create_canvas(self.file) button1 = tk.Button(self.frame_ll, text=’上一張’, width=10, height=1, command=self.pre_picture) button1.pack() button2 = tk.Button(self.frame_rr, text=’下一張’, width=10, height=1, command=self.next_picture) button2.pack() self.button_list.append(button1) self.button_list.append(button2) self.object_list.extend(self.button_list) else: self.is_show = True while self.object_list:o = self.object_list.pop()o.destroy() def new_button(self): ’’’創建展示按鈕’’’ tk.Button(self.frame_l, text=’圖片展示’, width=10, height=1, command=self.show_picture).pack() def create_canvas(self,file): ’’’用畫布展示圖片’’’ self.image_file = tk.PhotoImage(file=file) canvas = tk.Canvas(self.frame_r, height=500, width=600) canvas.create_image(1, 1, anchor=’nw’, image=self.image_file) canvas.pack() self.object_list.append(canvas) def run(self): ’’’主程序調用’’’ self.window.mainloop()if __name__ == ’__main__’: w = Window() w.new_button() w.run()

樣式如下:有點丑,不過功能沒毛病,就先這么著吧~~~

python tkiner實現 一個小小的圖片翻頁功能的示例代碼

點擊圖片展示之后

python tkiner實現 一個小小的圖片翻頁功能的示例代碼

上一頁下一頁可以用,再次點擊圖片展示

python tkiner實現 一個小小的圖片翻頁功能的示例代碼

總結

到此這篇關于python tkiner實現 一個小小的圖片翻頁功能的文章就介紹到這了,更多相關python tkiner實現圖片翻頁內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 又爽又刺激的欧美毛片 | 欧美日韩综合网在线观看 | 免费观看国产网址你懂的 | 亚洲黄色网址在线观看 | 国产精品videosse | 91精品免费观看老司机 | 黄色大片网站在线观看 | 97r久久精品国产99国产精 | 国产成人精品免费视 | 37pao成人国产永久免费视频 | 亚洲欧美日本人成在线观看 | 亚洲狠狠婷婷综合久久久久 | 91好色视频 | 国产精品青草久久 | 成人的天堂视频一区二区三区 | 亚洲综合色婷婷中文字幕 | 欧美三级在线观看不卡视频 | 色综合免费视频 | 国产一区二区三区四 | 免费看欧美一级特黄α大片 | 看一级特黄a大片日本片黑人 | 久久国产精品一国产精品金尊 | 日韩欧美一级a毛片欧美一级 | 日韩手机在线视频 | 在线观看搡女人 | 97精品在线视频 | 国产大秀视频在线一区二区 | 黄色在线免费看 | 亚洲一在线 | 亚洲综合欧美 | 孕妇三片高清在线观看 | 娇小性色xxxxx| 自偷自偷自亚洲首页精品 | 色婷婷久久综合中文久久一本` | 可以免费观看的黄色网址 | 午夜激情影院 | 日韩视频亚洲 | 色涩亚洲 | 亚洲国产剧情在线 | 国内精品久久久久影院6 | 可以免费观看的毛片 |