import Tkinter
import tkMessageBox
import xlwt
from xlrd import open_workbook
from tempfile import TemporaryFile
from xlwt import Workbook
import tkSimpleDialog
import tkMessageBox
from tkFileDialog import *
top = Tkinter.Tk()
#FSR
def fsr():
tkMessageBox.showinfo("Open", "Select Feedback file")
filename1 = askopenfilename(filetypes=[("Excel worksheets","*.xls")])
if filename1=='':
tkMessageBox.showerror('Error', 'All files must be uploaded')
fsr()
B1 = Tkinter.Button(top, text = "Details upload", command = fsr)
B1.pack()
top.mainloop()
wb1 = open_workbook(filename1)
sheet1 = wb1.sheet_by_index(0)
batch = []
print "****"
for row in range(sheet1.nrows):
if(row!=0):
batch.append(sheet1.cell(row,16).value)
print "****"
此代码段不会在控制台上打印任何内容。打印“****”无效。而且,如果发出top.mainloop(),则不会显示tk窗口。怎么解决这个问题?
答案 0 :(得分:1)
将代码放在import Tkinter
import tkMessageBox
import xlwt
from xlrd import open_workbook
from tempfile import TemporaryFile
from xlwt import Workbook
import tkSimpleDialog
import tkMessageBox
from tkFileDialog import *
#FSR
def fsr():
while True:
tkMessageBox.showinfo("Open", "Select Feedback file")
filename1 = askopenfilename(filetypes=[("Excel worksheets","*.xls")])
if filename1:
break
tkMessageBox.showerror('Error', 'All files must be uploaded')
wb1 = open_workbook(filename1)
sheet1 = wb1.sheet_by_index(0)
batch = []
print "****"
for row in range(sheet1.nrows):
if(row!=0):
batch.append(sheet1.cell(row,16).value)
print "****"
top = Tkinter.Tk()
B1 = Tkinter.Button(top, text="Details upload", command=fsr)
B1.pack()
top.mainloop()
中,如下所示:
app/views/wordclouds