这是我的代码。它运行良好,但问题是创建的Tkinter窗口在我单击2-3次后才显示任何数据。请指导我。另外,如果您可以指导我如何最大化tk窗口,这将是有帮助的,此处的最大化代码并没有完全最大化剩余的空间。
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name(
'perfect_credential.json', scope)
gc = gspread.authorize(credentials)
wks = gc.open("mysheet").sheet1
data = wks.get_all_values()
headers = data.pop(0)
DF = pd.DataFrame()
df = pd.DataFrame(data, columns=headers)
df1=df.loc[(df['City'] == "A") ]
df2=df.loc[(df['City'] == "B")]
df3=df.loc[(df['City'] == "C")]
df4=df.loc[(df['City'] == "D")]
df5=df.loc[(df['City'] == "E")]
df6=df.loc[(df['City'] == "F")]
df7=df.loc[(df['City'] == "G")]
class TestApp(Frame):
"""Basic test frame for the table"""
def __init__(self,parent=None):
self.parent = parent
Frame.__init__(self)
self.main = self.master
pad=0
self.main.geometry("{0}x{0}+0+0".format(
self.main.winfo_screenwidth()-pad, self.main.winfo_screenheight()-pad))
self.main.title('MYTK')
f = Frame(self.main)
def commandSCT():
DF=df
self.table = pt = Table(f, dataframe=DF,
showtoolbar=True, showstatusbar=True)
pt.show()
return
def command1():
DF=df1
self.table = pt = Table(f, dataframe=DF,
showtoolbar=True, showstatusbar=True)
pt.autoResizeColumns()
pt.show()
return
def command2():
DF=df2
self.table = pt = Table(f, dataframe=DF,
showtoolbar=True, showstatusbar=True)
pt.show()
return
def command3():
DF=df3
self.table = pt = Table(f, dataframe=DF,
showtoolbar=True, showstatusbar=True)
pt.show()
return
def command4():
DF=df4
self.table = pt = Table(f, dataframe=DF,
showtoolbar=True, showstatusbar=True)
pt.show()
return
def command5():
DF=df5
self.table = pt = Table(f, dataframe=DF,
showtoolbar=True, showstatusbar=True)
pt.show()
return
def command6():
DF=df6
self.table = pt = Table(f, dataframe=DF,
showtoolbar=True, showstatusbar=True)
pt.show()
return
def command7():
DF=df7
self.table = pt = Table(f, dataframe=DF,
showtoolbar=True, showstatusbar=True)
pt.show()
return
menubar= Menu(self.main)
filemenu=Menu(menubar)
filemenu.add_command(label="CITY A",command=commandSCT)
filemenu.add_command(label="CITY B",command=command1)
filemenu.add_command(label="CITY C",command=command2)
filemenu.add_command(label="CITY D",command=command3)
filemenu.add_command(label="CITY E",command=command4)
filemenu.add_command(label="CITY F",command=command5)
filemenu.add_command(label="CITY G",command=command6)
filemenu.add_command(label="CITY H",command=command7)
filemenu.add_separator()
menubar.add_cascade(label="City", menu=filemenu)
Tk.config(self.main,menu=menubar)
f.pack(fill=BOTH,expand=1)
app=TestApp()
app.mainloop()