Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 没有在控制台上打印任何内容_Python_Python 2.7_Tkinter_Xlrd_Xlwt - Fatal编程技术网

Python 没有在控制台上打印任何内容

Python 没有在控制台上打印任何内容,python,python-2.7,tkinter,xlrd,xlwt,Python,Python 2.7,Tkinter,Xlrd,Xlwt,此代码段不会在控制台上打印任何内容。打印“**”无效。而且,如果发出top.mainloop(),则tk窗口不会显示。如何解决此问题?将代码放入fsr如下: import Tkinter import tkMessageBox import xlwt from xlrd import open_workbook from tempfile import TemporaryFile from xlwt import Workbook import tkSimpleDialog import tkM

此代码段不会在控制台上打印任何内容。打印“**”无效。而且,如果发出top.mainloop(),则tk窗口不会显示。如何解决此问题?

将代码放入
fsr
如下:

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 "****"

修正你的缩进。您的代码无法命名。实际代码中的缩进是正确的。在这里复制的时候可能搞砸了。请告知代码有什么问题。按照您的建议更正缩进。请现在检查..你的打印报表对我有效。当然,在你摧毁窗户之前它不会工作,但在那之后它就可以正常工作了。您是否知道
mainloop
在小部件销毁之前不会返回,因此在小部件返回之前不会运行任何代码?是的。我知道。但是如何使在mainloop()函数之后编写的代码工作呢?我是xlrd和Tinker的新手。这就是我无法理解的原因。请帮忙。
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()