• tkinter


    
    
    #! /usr/bin/env python
    # -*- coding: utf-8 -*-
    # Created by 张文思 at 2019/9/4 0004

    from tkinter import *
    from tkinter import filedialog
    from tkinter.filedialog import askdirectory


    class QMainWindow():

    def __init__(self, window):
    self.window = window
    window.geometry('300x300')
    # 定义变量,用户选择文件名的存放显示。tip:下面一定要加括号
    self.input = StringVar()
    self.radioflag = IntVar()

    # 标题
    Label(window, text='调度控制管理器', bg='yellow', width=20).pack(side='top', fill='x')
    # 定义左边导航frame
    self.leftSideFra = Frame(window, width=100, bg='pink')
    self.leftSideFra.pack(side='left', fill='y')
    self.defineLeft()

    # 定义内容
    self.contentFra = Frame(window, width=200, bg='grey')
    self.contentFra.pack(side='right',fill='both')
    self.contendTop = Frame(self.contentFra)
    self.contendTop.pack(side='top')

    def defineLeft(self):
    compreBtfrm = Frame(self.leftSideFra)
    compreBtfrm.pack(side='top')
    Button(compreBtfrm, bitmap="info", text="综合能率", width=100, height=20, compound=LEFT,
    command=self.showRadioButton).pack(side='top')

    def showRadioButton(self):
    """
    :return:
    """
    print(123)
    self.contendTop.pack_forget()
    Radiobutton(self.contendTop, text="单文件", variable=self.radioflag, value=1, command=self.onclick).pack()
    Radiobutton(self.contendTop, text="文件夹", variable=self.radioflag, value=2, command=self.onclick).pack()

    def onclick(self):
    if self.radioflag.get() == 1:
    self.showfile()
    else:
    self.showDirectory()

    def showfile(self):
    """
    选择单文件上传
    :return:
    """

    def selectFile(file):
    # path_ = askdirectory() //选择路径
    filename_ = filedialog.askopenfilename() # 选择文件
    file.set(filename_)

    Label(self.window, text="目标文件:").grid(row=2, column=0)
    Entry(self.window, textvariable=self.input).grid(row=2, column=1)
    Button(self.window, text="浏览", command=lambda: selectFile(self.input)).grid(row=2, column=2)

    def showDirectory(self):
    """
    选择整个文件夹上传,只会过滤file为xlsx的文件
    :return:
    """

    def selectPath(path):
    path_ = askdirectory()
    path.set(path_)

    Label(self.window, text="目标路径:").grid(row=0, column=0)
    Entry(self.window, textvariable=self.input).grid(row=0, column=1)
    Button(self.window, text="浏览", command=lambda: selectPath(self.input)).grid(row=0, column=2)


    # main方法
    if __name__ == '__main__':
    window = Tk()

    qw = QMainWindow(window)
    # 弹出文件选择器,判断让用户选择抽取方式
    # button = qw.showRadioButton()
    window.mainloop()



    --------------------

    import tkinter

    wuya = tkinter.Tk()
    wuya.title("wuya")
    wuya.geometry("300x200+10+20")

    # 创建lable标签
    lb = tkinter.Label(wuya,text='请选择您的性别:',fg='blue')
    lb.pack()

    # 定义选择后执行的函数
    def func():
    mg = ''
    mg += str(r.get())

    text.delete(0.0,tkinter.END)
    text.insert('insert',mg)


    # 创建单选项
    r = tkinter.IntVar()
    radioflag = tkinter.IntVar()
    male_select = tkinter.Radiobutton(wuya,text='男',value=1,variable=r,command=func)
    male_select.pack()
    female_select = tkinter.Radiobutton(wuya,text='女',value=2,variable=r,command=func)
    female_select.pack()
    tkinter.Radiobutton(wuya, text="单文件", variable=radioflag, value=1).pack()
    tkinter.Radiobutton(wuya, text="文件夹", variable=radioflag, value=2).pack()
    #
    # 创建文本框
    text = tkinter.Text(wuya,width=30,height=3)
    text.pack()

    wuya.mainloop()
    欢迎对it热情的同学,加qq进行技术讨论; QQ:850922253
  • 相关阅读:
    Metadata Lock原理5
    Seconds_Behind_Master
    Metadata Lock原理4
    MySQL Troubleshoting:Waiting on query cache mutex 腾讯数据库工程师:幕南风
    Metadata Lock原理2
    Metadata Lock原理1
    Online DDL与pt-online-schema-change
    Solaris 安装JDK
    RAID 概述
    4K Block Size的Device和 Aligned IO
  • 原文地址:https://www.cnblogs.com/zhangwensi/p/11460774.html
Copyright © 2020-2023  润新知