У меня есть основной фрейм tkinter и фрейм просмотра списка, когда я попытался объединить, поместив просмотр списка в мой основной фрейм tkinter, похоже, он не работает. У меня есть в общей сложности 4 кадра, стартовая страница, PageOne, PageTwo, PageThree.
Список представлен в моем фрейме "PageThree". мой список просмотра работает сам по себе, но когда я включаю его в свой мэйнфрейм, он, похоже, не запускается. Я пытаюсь сделать так, чтобы, когда я перехожу к моему «PageThree» фрейм, мой список просмотра там.
import Tkinter as tk # python 2
import ttk
from function4 import *
from testgui import *
import tkFont as tkfont # python 2
import tkFileDialog as fd
from PIL import ImageTk, Image
def get_file_name(file_entry):
file_name = fd.askopenfilename(title="Select file", filetypes=(("CSV Files", "*.csv"),))
file_entry.insert(0, file_name)
class SampleApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.title_font = tkfont.Font(family='Helvetica', size=18, weight="bold", slant="italic")
image = Image.open('pythonbackground.png')
photo = ImageTk.PhotoImage(image)
label = tk.Label(self, image=photo)
label.image = photo # keep a reference!
label.place(x=0, y=0, relwidth=1, relheight=1)
# the container is where we'll stack a bunch of frames
# on top of each other, then the one we want visible
# will be raised above the others
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, PageOne, PageTwo, PageThree):
page_name = F.__name__
frame = F(parent=container, controller=self)
self.frames[page_name] = frame
# put all of the pages in the same location;
# the one on the top of the stacking order
# will be the one that is visible.
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame("StartPage")
def show_frame(self, page_name):
'''Show a frame for the given page name'''
frame = self.frames[page_name]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This is the start page", font=controller.title_font)
label.pack(side="top", fill="x", pady=10)
button1 = tk.Button(self, text="Go to Page One", command=lambda: controller.show_frame("PageOne"))
button2 = tk.Button(self, text="Go to Page Two", command=lambda: controller.show_frame("PageTwo"))
button3 = tk.Button(self, text="Go to Page Three", command=lambda: controller.show_frame("PageThree"))
button1.pack()
button2.pack()
button3.pack()
class PageOne(tk.Frame):
def get_file_name(file_entry):
file_name = fd.askopenfilename(title="Select file", filetypes=(("CSV Files", "*.csv"),))
file_entry.delete(0, tk.END)
file_entry.insert(0, file_name)
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
entry_csv = tk.Entry(self, text="", width=80, font=20)
entry_csv.place(x=250, y=380)
entry_csv2 = tk.Entry(self, text="", width=80, font=20)
entry_csv2.place(x=250, y=500)
label = tk.Label(self, bg="#64dd17", height=10, font=30, text="1002 Dataset Analyzer")
label.pack(fill="x")
label = tk.Label(self, text="1st Dataset File: ", font=30)
label.place(x=100, y=380)
button = tk.Button(self, text="Browse...", width=10, height=2, command=lambda: get_file_name(entry_csv))
button.place(x=1000, y=370)
label = tk.Label(self, text="2nd Dataset File:", font=30)
label.place(x=100, y=500)
button = tk.Button(self, text="Browse...", width=10, height=2, command=lambda: get_file_name(entry_csv2))
button.place(x=1000, y=490)
#button = tk.Button(self, text="Upload", command=run_and_close, width=10, height=2)
#button.place(x=1250, y=430)
class PageTwo(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
"""above codes are important"""
label = tk.Label(self, bg="#64dd17", height=10, font=30, text="OPEN FUNCTION")
label.pack(fill="x")
button = tk.Button(self, text="Function 2", height=2, font=100,
command=lambda: controller.show_frame("StartPage"), fg='black', width=50)
button.place(x=30, y=400)
button = tk.Button(self, text="Function 3", height=2, font=100,
command=lambda: controller.show_frame("StartPage"),
fg='black', width=50)
button.place(x=30, y=460)
button = tk.Button(self, text="Function 4", height=2, font=100,
command=lambda: controller.show_frame("StartPage"),
fg='black', width=50)
button.place(x=30, y=520)
button = tk.Button(self, text="Function 5", height=2, font=100,
command=lambda: controller.show_frame("StartPage"),
fg='black', width=50)
button.place(x=30, y=580)
button = tk.Button(self, text="Function 6", height=2, font=100,
command=lambda: controller.show_frame("StartPage"),
fg='black', width=50)
button.place(x=30, y=640)
button = tk.Button(self, text="GO TO OPEN FUNCTION", height=2, font=100,
command=lambda: controller.show_frame("PageThree"),
fg='red', width=50)
button.place(x=30, y=700)
class PageThree(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
"""above codes are important"""
self.root = tk.Tk()
treeView = ttk.Treeview(self, height=25)
self.resizable(width=False, height=False)
# set up the columns and headings
# In reality "Member ID" would be exported from the database
self.treeView["columns"] = ["CompanyName", "AwardedAmount"]
self.treeView["show"] = "headings"
self.treeView.heading("CompanyName", text="Company Name")
self.treeView.heading("AwardedAmount", text="Awarded Amount")
self.treeView.grid(columnspan=2)
self.treeView.column("CompanyName", minwidth=0, width=480, stretch="no")
self.treeView.column("AwardedAmount", minwidth=0, width=200, stretch="no")
self.vsb = ttk.Scrollbar(orient="vertical", command=treeView.yview)
self.vsb.pack(side="right", fill="y")
self.treeView.configure(yscrollcommand=self.vsb.set)
self.treeView.pack(expand="yes", fill="both")
# Add content using (where index is the position/row of the treeview)
# iid is the item index (used to access a specific element in the treeview)
# you can set iid to be equal to the index
#tuples = top5_company(reg_award, non_reg_award)
dict = eachSectorTotalAmtProcurement("government-procurement-via-gebiz.csv")
index = iid = 0
for values in dict.items():
# for values in dict:
print values
treeView.insert("", 'end', values=values)
index = iid = index + 1
self.root.mainloop()
if __name__ == "__main__":
app = SampleApp()
app.title("ICT1002 PROJECT")
app.iconbitmap(r'sitlogo_Ncr_icon.ico')
"""image = Image.open('pythonbackground.png')
photo = ImageTk.PhotoImage(image)
label = tk.Label(app, image=photo)
label.image = photo # keep a reference!
label.pack(fill="both", expand="yes")"""
app.state("zoomed")
app.mainloop()