我使用Pywin32库。 以下代码段最多可读取6行和19列。如果我尝试阅读更多IDLE ppython gui(32位)似乎正在循环中。程序既不退出也不给我一个错误。 这是正确的行为吗?
以下是代码:
import tkinter as tk
from win32com.client import Dispatch
from tkinter import *
#from tkinter import ttk
#import tkinter
class Example(tk.Frame):
def __init__(self, root):
root.title('AAAA')
tk.Frame.__init__(self, root, width=0, height=0)
self.canvas = tk.Canvas(root, width=1000, height=550) #grandezza finestra
self.frame = tk.Frame(self.canvas)
self.vsb = tk.Scrollbar(root, orient="horizontal", command=self.canvas.xview)
self.canvas.configure(xscrollcommand=self.vsb.set)
self.vsb.pack(side="bottom", fill="x")
self.canvas.pack(side="top", fill="both", expand=True)
self.canvas.create_window((4,4), window=self.frame, anchor="nw",
tags="self.frame")
self.vsb = tk.Scrollbar(root, orient="vertical", command=self.canvas.yview)
self.canvas.configure(yscrollcommand=self.vsb.set)
self.vsb.pack(side="right", fill="y")
self.canvas.pack(side="left", fill="both", expand=True)
self.canvas.create_window((4,4), window=self.frame, anchor="nw",
tags="self.frame")
self.titoli_HFT = ["1", "1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","9"]
for i in range (0,len(self.titoli_HFT)):
self.lblnome=tk.Label(self.frame, text= self.titoli_HFT[i], font=("Helvetica", 8))
self.lblnome.grid(row=2, column=i+1, padx=5, pady=15) #place(x=85+j, y=50)
self.frame.bind("<Configure>", self.onFrameConfigure)
self.lettura()
def onFrameConfigure(self, event):
'''Reset the scroll region to encompass the inner frame'''
self.canvas.configure(scrollregion=self.canvas.bbox("all"))
def lettura(self):
xl= Dispatch("Excel.Application")
xl.Visible = True
#x2= Dispatch("Excel.Application")
#x2.Visible = True
self.checkb_intvar = list() #contiene una lista di 1 o 0 associati alle checkbox nella lista quadratini
self.quadratiniH = list()
self.quadratiniB = list()
#self.quadratiniB = l = [None] * (13 * len(self.titoli_BFT) )
#self.quadratiniH = l = [None] * (13 * len(self.titoli_HFT) )
wbH = xl.Workbooks.Open(r'C:\Users\\Marco\\LAVORO\\Smith&Nephew\\appRonca\\fonte\\HFT_SAP_2.csv')
print("wbH")
wsH=wbH.WorkSheets(1) # get a reference to the first sheet
MAX = 6
#HEADER HEADER HEADER HEADER
for i in range(0, MAX):
#CHECKBOX
self.checkb_intvar.append (IntVar())
self.quadratiniH.append(tk.Checkbutton(self.frame, text="", variable=self.checkb_intvar[i], onvalue=True))
self.quadratiniH[i].grid(column=0, row=i+3) #spunta
for j in range(0,len(self.titoli_HFT)):
print("for for")
contvalueX = i + 1 #con zero da errore allora +1
contvalueY = j + 1 #con zero da errore allora +1
self.txt1 = tk.Text(self.frame, width='10', height='1')
if (wsH.Cells(contvalueX, contvalueY ).Value != None):
self.txt1.insert('1.0', wsH.Cells(contvalueX, contvalueY ).Value)#ws.Cells(1,i).Value
self.txt1.tag_add("start", "1.0", "1.13")
if (contvalueY == 1 ): #### qui si richiama la funziona regole con tutte le regole
self.txt1.tag_config("start", background="white", foreground="red")
self.txt1.grid(row=i+3, column=j+1, padx=5, pady=15)
print("if")
else:
print("else")
self.txt1.insert('1.0', "")
self.txt1.grid(row=i+3, column=j+1, padx=5, pady=15)
if (contvalueY == 1 ): #### qui si richiama la funziona regole con tutte le regole
self.txt1.tag_config("start", background="white", foreground="red")
wbH.Close()
xl.Quit()
if __name__ == "__main__":
root=tk.Tk()
Example(root).pack(side="top", fill="both", expand=True)
root.mainloop()
我哪里错了?