账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    tkinter主窗口和子窗口同时弹出该怎么办?
    92
    0

    这是一个小程序:运行后主窗口打开。点击Click Me按钮,应该弹出一个文件夹选择窗口,选择好文件夹点击确认后,将文件夹中的文件(不包括隐藏文件和子文件夹)的名称前面加上序号。在按钮下面显示已处理的文件数量。

    目前我的代码存在两个主要问题:
    (1)主窗口和子窗口同时弹出了;
    (2)未能筛选出隐藏文件(macos系统)。
    希望能指点!谢谢!

    import os  
    from tkinter import filedialog  
    import tkinter as tk  
    from tkinter import Button  
      
    class ReName():  
        def __init__(self):  
            self.n = 0  
      
      def rename(self):  
      
            file_path = filedialog.askdirectory(title='ReNamer')  
            file_lists = os.listdir(file_path)  
            for file in file_lists.copy():  
                oldname = file_path + os.sep + file  
                if os.path.isdir(oldname):  
                    continue  
     else:  
                    newname = file_path + os.sep + '(' + str(self.n + 1) + ')' + file  
                    os.rename(oldname, newname)  
                    self.n+=1  
      print(self.n)  
      
      
    root=tk.Tk()  
    root.geometry("550x200")  
    label=tk.Label(root,font=("Arial Bold",15),  
                   text='Please select a directory to rename files in the folder:')  
    label.pack()  
    ins=ReName()  
    btn=Button(root,font=("Arial",15),bg='orange',text="Click Me",command=ins.rename())  
    btn.pack()  
    print(ins.n)  
    label=tk.Label(root,text=str(ins.n)+' file(s) renamed.')  
    label.pack()  
    root.mainloop()
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部