在我更改代码以适应对我的函数的调用后,按钮不再显示

问题描述

我想要实现的是让 3 个按钮出现在同一个窗口中。每个按钮调用不同的功能。如果单击一个按钮,它应该调用指定的函数。单击一个按钮时,所有按钮的窗口应该消失,程序结束。

知道我做错了什么以及如何获得正确代码以实现我想要实现的目标吗?

谢谢!

import os
import tkinter.filedialog
import pathlib
from os import rename
from tkinter import simpledialog,Button
import getpass

# File types list
ftypes = [
    ('Python code files','*.py'),('Perl code files','*.pl;*.pm'),('Java code files','*.java'),('C++ code files','*.cpp;*.h'),('Text files on mac','*.rtf'),('Text files','*.txt'),("PDF files","*.pdf"),('All files','*'),]


# The function renames and relocates selected files depending on the sorting selected
def creation():
    lst.sort(key=os.path.getctime)
    num = 1
    for line in lst:
        dst = newpath + name + str(num) + suffix
        rename(line,dst)
        num += 1


def lastmodified():
    lst.sort(key=os.path.getmtime)
    num = 1
    for line in lst:
        dst = newpath + name + str(num) + suffix
        rename(line,dst)
        num += 1


def lastaccessed():
    lst.sort(key=os.path.getatime)
    num = 1
    for line in lst:
        dst = newpath + name + str(num) + suffix
        rename(line,dst)
        num += 1


def hide(root):
    root.withdraw()


def buttons():
    root.geometry('100x100')

    btncreation = Button(root,text='Order by Creation',bd='5',command=creation)
    btncreation.pack(side='top')

    btnmodified = Button(root,text='Order by Last Modified',command=lastmodified)
    btnmodified.pack(side='top')

    btnaccessed = Button(root,text='Order by Last Accessed',command=lastaccessed)
    btnaccessed.pack(side='top')
    root.mainloop()


root = tkinter.Tk()

hide(root)

# Window to select files to order
filez = tkinter.filedialog.askopenfilenames(title='Select files to rename (must be all of the same type!)')

'''
for line in filez:
    time.ctime(os.path.getctime(line))
'''

# List populated with file names
lst = list(filez)

# Saves the extension of the selected files
suffix = pathlib.Path(lst[0]).suffix


# Window to get user input on file naming
root = tkinter.Tk()
hide(root)
root.geometry("400x240")

ROOT = tkinter.Tk()

ROOT.withdraw()

# Asks user for file names,while loop won't break if no name is given
USER_INP = simpledialog.askstring(title="File Names",prompt="Name your files:")

while USER_INP == '':
    USER_INP = simpledialog.askstring(title="File Names",prompt="Name your files:")

# Gets username for path use
username = getpass.getuser()

name = USER_INP

# Asks user for folder name,while loop won't break if no name is given
USER_INP2 = simpledialog.askstring(title="Folder Name",prompt="Name your folder:")

while USER_INP2 == '':
    USER_INP2 = simpledialog.askstring(title="Folder Name",prompt="Name your folder:")

foldername = USER_INP2

# Creates new folder for ordered files,if folder exists,it uses it
newpath = r'/Users/' + username + '/Desktop/' + foldername + '/'
if not os.path.exists(newpath):
    os.makedirs(newpath)

buttons()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...