0
我已经用Python编写了一个程序,允许我一次更改多个文件的名称。我有一个很奇怪的问题。raw_input停止GUI出现
当我使用raw_input来获得我想要的扩展名时,GUI将不会启动。我没有得到任何错误,但窗口永远不会出现。
我尝试使用raw_input作为从用户获取文件扩展名的方式来构建文件列表。当raw_input未被使用时,这个程序将正常工作。我指的代码段在我的globList函数中。出于某种原因,当使用raw_imput时,窗口将不会启动。
import os
import Tkinter
import glob
from Tkinter import *
def changeNames(dynamic_entry_list, filelist):
for index in range(len(dynamic_entry_list)):
if(dynamic_entry_list[index].get() != filelist[index]):
os.rename(filelist[index], dynamic_entry_list[index].get())
print "The files have been updated!"
def drawWindow(filelist):
dynamic_entry_list = []
my_row = 0
my_column = 0
for name in filelist:
my_column = 0
label = Tkinter.Label(window, text = name, justify = RIGHT)
label.grid(row = my_row, column = my_column)
my_column = 1
entry = Entry(window, width = 50)
dynamic_entry_list.append(entry)
entry.insert(0, name)
entry.grid(row = my_row, column = my_column)
my_row += 1
return dynamic_entry_list
def globList(filelist):
#ext = raw_input("Enter the file extension:")
ext = ""
desired = '*' + ext
for name in glob.glob(desired):
filelist.append(name)
filelist = []
globList(filelist)
window = Tkinter.Tk()
user_input = drawWindow(filelist)
button = Button(window, text = "Change File Names", command = (lambda e=user_input: changeNames(e, filelist)))
button.grid(row = len(filelist) + 1 , column = 1)
window.mainloop()
这是raw_input的问题吗?
什么是解决问题的好方法?
您使用的是IDE:
在弹出对话框一个体面的教程可以在effbot网站上找到? – Kevin