Home > other >  Batch file name instead of small programs, pop-up both tkinter components
Batch file name instead of small programs, pop-up both tkinter components

Time:10-01

Just started to learn tkinter, the use of components are not familiar with, want to perfect this small program, the function of the design is as follows, pop up a window after operation, the upper is a label, which is an address bar, you can select a folder, then here is a sign that said "Click Me" orange button, Click the button, after file from the folder (not including the hidden files and subfolders and files) in a with a brace and the serial number, the name of the task is completed, in how many files are displayed on the bottom of the batch processing,

My code has the following problems:
The main window and select the folder window (not the address bar) pop up at the same time,

Please help to modify the following code
Renamer_V1. Py:

 
the import the OSThe import win32file
The import win32con
The import tkinter as tk
The from tkinter import Button
The from clicked import clicked

Root=tk. Tk ()
Root. Geometry (" 550 x200 ")
Label=tk. Label (root, the font=(" Arial Bold ", 15), the text='both Please select a directory to rename files in the folder:')
Label. Pack ()
C=Clicked ()
BTN=Button (root, the font=(" Arial ", 15), bg='orange', the text="Click Me", the command=Arthur c. licked)
BTN. Pack ()

Arthur c. licked ()
File_lists=OS. Listdir (c.f ile_path)
N=0

For file in file_lists. Copy () :
Oldname=c.f ile_path + OS. Sep + file
File_flag=win32file. GetFileAttributesW (oldname)
Is_hiden=file_flag & amp; Win32con. FILE_ATTRIBUTE_HIDDEN

If OS. Path. Isdir (oldname) or is_hiden:
The continue
The else:
Oldname=c.f ile_path + OS. Sep + file
Newname=c.f ile_path + OS. Sep + '(' + STR (n + 1) +') '+ file
OS. Rename (oldname, newname)
N +=1
Label=tk. Label (root, text=STR (n) + 'file (s) renamed.')
Label. Pack ()
Root. Mainloop ()


Clicked. Py:
 
The from tkinter import filedialog

The class Clicked:
File_path=None

Def __init__ (self) :
Print ()

Def clicked (self) :
The self. The file_path=filedialog. Askdirectory (title='ReNamer')

  • Related