日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python支持gui编程_Python GUI编程完整示例

發布時間:2023/12/10 python 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python支持gui编程_Python GUI编程完整示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本文實例講述了python gui編程。分享給大家供大家參考,具體如下:

import os

from time import sleep

from tkinter import *

from tkinter.messagebox import showinfo

class dirlist(object):

def __init__(self, initdir=none):

self.top = tk()

self.label = label(master=self.top, text='directory lister v1.0')

self.label.pack()

self.cwd = stringvar(master=self.top)

self.dirl = label(self.top, fg='blue', font=('helvetica', 14, 'bold'))

self.dirl.pack()

self.dirfm = frame(master=self.top)

self.dirsb = scrollbar(master=self.dirfm)

self.dirsb.pack(side=right,fill=y)    # fill=y,垂直填充空間排列

self.dirs = listbox(master=self.dirfm, height=15, width=50, yscrollcommand=self.dirsb.set)

self.dirs.bind('', func=self.setdirandgo)   # ,雙擊顯示路徑列表

self.dirsb.config(command=self.dirs.yview)

self.dirs.pack(side=left, fill=both)

self.dirfm.pack()

self.dirn = entry(master=self.top, width=50, textvariable=self.cwd)

self.dirn.bind('', func=self.dols)

self.dirn.pack()

self.bfm = frame(master=self.top)

self.cleer = button(master=self.bfm, text='清除', command=self.clrdir, activeforeground='white',

activebackground='blue')

self.ls = button(master=self.bfm, text='顯示列表', command=self.dols, activeforeground='white',

activebackground='green')

self.quit = button(master=self.bfm, text='退出', command=self.top.quit, activeforeground='white',

activebackground='red')

self.cleer.pack(side=left)

self.ls.pack(side=left)

self.quit.pack(side=left)

self.bfm.pack()

if initdir:

self.cwd.set(os.curdir)

self.dols()

def setdirandgo(self, ev=none):

self.last = self.cwd.get()

self.dirs.config(selectbackground='red')

chek = self.dirs.get(self.dirs.curselection())

if not chek:

chek = os.curdir

self.cwd.set(chek)

self.dols()

def dols(self, ev=none):

error = ''

tdir = self.cwd.get()

if not tdir:

tdir = os.curdir

if not os.path.exists(tdir):

error = tdir + ':未找到文件,請檢查路徑!'

elif not os.path.isdir(tdir):

error = tdir + ':不是一個路徑!'

if error:

# self.cwd.set(error)

showinfo(title='提示',message=error)

self.top.update()

# sleep(2)

if not (hasattr(self, 'last') and self.last):

self.last = os.curdir

self.cwd.set(self.last)

self.dirs.config(selectbackground='lightskyblue')

self.top.update()

return

if not os.path.isdir(tdir):

self.cwd.set('')

else:

self.cwd.set('獲取目錄內容中...')

self.top.update()

dirlist = os.listdir(tdir)

dirlist.sort()

os.chdir(tdir)

self.dirl.config(text=os.getcwd())

self.dirs.delete(0, end)

self.dirs.insert(end, os.curdir)

self.dirs.insert(end, os.pardir)

for eachfile in dirlist:

self.dirs.insert(end, eachfile)

self.cwd.set(os.curdir)

self.dirs.config(selectbackground='lightskyblue')

def clrdir(self, ev=none):

self.cwd.set('')

if __name__ == '__main__':

dir = dirlist(os.curdir)

mainloop()

效果如下:

希望本文所述對大家python程序設計有所幫助。

希望與廣大網友互動??

點此進行留言吧!

總結

以上是生活随笔為你收集整理的python支持gui编程_Python GUI编程完整示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。