python点击button创建对话框读取文件。
from tkinter import *
import tkinter as tk
from tkinter import filedialog
from demo import *
# 通过对话框获取文件路径
def getPathByDialog():
root = tk.Tk()
root.withdraw()
#Folderpath = filedialog.askdirectory() #获得选择好的文件夹
Folderpath = filedialog.askopenfilename() #获得选择好的文件
print('Folderpath:', Folderpath)
parser = argparse.ArgumentParser(
description='''Lightweight human pose estimation python demo.
This is just for quick results preview.
Please, consider c++ demo for the best performance.''')
parser.add_argument('--checkpoint-path', type=str, default='checkpoint_iter_370000.pth', help='path to the checkpoint')
parser.add_argument('--height-size', type=int, default=256, help='network input layer height size')
parser.add_argument('--video', type=str, default=Folderpath, help='path to video file or camera id')
parser.add_argument('--images', nargs='+', default='2.png', help='path to input image(s)')
parser.add_argument('--cpu', action='store_true', help='run network inference on cpu')
parser.add_argument('--track', type=int, default=1, help='track pose id in video')
parser.add_argument('--smooth', type=int, default=1, help='smooth pose keypoints')
args = parser.parse_args()
if args.video == '' and args.images == '':
raise ValueError('Either --video or --image has to be provided')
net = PoseEstimationWithMobileNet()
checkpoint = torch.load(args.checkpoint_path, map_location='cpu')
load_state(net, checkpoint)
#frame_provider = ImageReader(args.images)
if args.video != '':
frame_provider = VideoReader(args.video)
else:
args.track = 0
run_demo(net, frame_provider, args.height_size, args.cpu, args.track, args.smooth)
#print('Filepath:',Filepath)
root =Tk()
root.title('登录')
root.geometry('400x200')
root.config(bg='#ffcc00')
Label(root,text='用户名',width=6).place(x=1,y=1)
Entry(root,width=20).place(x=45,y=1)
Label(root,text='密码',width=6).place(x=1,y=20)
Entry(root,width=20,show='*').place(x=45,y=20)
Button(root,text='登录',width=8).place(x=40,y=40)
Button(root,text='取消',width=8).place(x=110,y=40)
Button(root, text='Button', command=lambda :getPathByDialog()).place(x=110,y=60)
root.mainloop()

浙公网安备 33010602011771号