I have this code in tkinter, all in one file, where I have a main window that has a frame as a menu and another frame that is the main screen. The menu calls other frames that are defined with their respective content. What I want to do is to pass each one of these frames, as inicio_page() to another file so that the code is not so long and also to be able to call them to the main file and that it is still functional.
Actually an example would be like this
from tkinter import *
import tkinter as tk
class App(tk.Tk):
def __init__(self):
super().__init__()
self.title("Test")
app_width = 1300
app_height = 720
screen_width = self.winfo_screenwidth()
screen_height = self.winfo_screenheight()
x = (screen_width /2) - (app_width / 2)
y = (screen_height /3) - (app_height / 3)
self.geometry(f"{app_width}x{app_height}+{int(x)}+{int(y)}")
self.minsize(width=1300, height=720)
self.maxsize(width=1920, height=1080)
backg = PhotoImage(file="img/trineside.png")
backg1 = PhotoImage(file="img/prueba4.png")
def delete_pages():
for frame in main_frame.winfo_children():
frame.destroy()
def indicate(lb, page):
hide_indicators()
lb.config(bg="white")
delete_pages()
page()
def hide_indicators():
page1_indicate.config(bg="#124e6b")
page2_indicate.config(bg="#124e6b")
menu_frame = tk.Frame(self, bg="#124e6b", highlightbackground="black", highlightthickness=1)
menu_frame.pack(side=tk.LEFT)
menu_frame.pack_propagate(False)
menu_frame.configure(width=195, height=1020)
background_menuframe= Label(menu_frame, image=backg)
background_menuframe.place(x=0, y=0, relwidth=1, relheight=1)
inicio_btn = tk.Button(menu_frame, text="Page1", font=("Bold", 18), fg="white", bd=0, bg="#124e6b", padx=56, activebackground='#124e6b', command=lambda: indicate(page1_indicate, inicio_page))
inicio_btn.place(x=10, y=100)
page1_indicate = tk.Label(menu_frame, text="", bg="#124e6b")
page1_indicate.place(x=3, y=100, width=5, height=43)
#########################################################
clientes_btn = tk.Button(menu_frame, text="Page2", font=("Bold", 18), fg="white", bd=0, bg="#124e6b",padx=40, command=lambda: indicate(page2_indicate, page_2))
clientes_btn.place(x=10, y=150)
page2_indicate = tk.Label(menu_frame, text="", bg="#124e6b")
page2_indicate.place(x=3, y=150, width=5, height=43)
#########################################################
main_frame = tk.Frame(self, highlightbackground="black", highlightthickness=1)
background_mainframe= Label(main_frame, image=backg1)
background_mainframe.place(x=0, y=0, relwidth=1, relheight=1)
main_frame.pack(side=tk.LEFT)
main_frame.pack_propagate(False)
main_frame.configure(height=1020, width=1750)
lb = tk.Label(main_frame, text="Try", font=("bold", 50))
lb.pack(pady=100)
def inicio_page():
background_mainframe= Label(main_frame, image=backg1)
background_mainframe.place(x=0, y=0, relwidth=1, relheight=1)
inicio_frame = tk.Frame(main_frame)
titulo_principal = tk.Label(main_frame,text="INICIO", font=("Bold", 15), bg="#031f3f", fg="white", height="2")
titulo_principal.pack(fill=tk.X)
inicio_frame.pack(pady=80)
#frames
f1_frame = tk.Frame(inicio_frame, bg="yellow", width=600, height=150)
f1_frame.pack()
f2_frame = tk.Frame(inicio_frame, width=500, height=400)
f2_frame.pack()
box1 = tk.Frame(f2_frame, height=20,width=250)
box1.grid(row=0, column=0)
box2 = tk.Frame(f2_frame, height=20,width=250)
box2.grid(row=0, column=1)
btn_logs = Button(box1,text="Abrir Logs",width=18)
btn_logs.pack(pady=20,padx=80)
btn_informes = Button(box2,text="Abrir Informes", width=18)
btn_informes.pack(pady=20,padx=80)
textof1 = Label(f1_frame, text="")
textof1.pack()
if __name__ == "__main__":
app = App()
app.mainloop()
What I did was to pass the inicio_page() function to another file and modify the button command to call the new class. My problem is that when I click on the button it does not show me the content that is in the InicioPage class.
I leave an example of what I tried.
from tkinter import *
import tkinter as tk
from frame_inicio import InicioPage
class App(tk.Tk):
def __init__(self):
super().__init__()
self.title("Test")
app_width = 1300
app_height = 720
screen_width = self.winfo_screenwidth()
screen_height = self.winfo_screenheight()
x = (screen_width /2) - (app_width / 2)
y = (screen_height /3) - (app_height / 3)
self.geometry(f"{app_width}x{app_height}+{int(x)}+{int(y)}")
self.minsize(width=1300, height=720)
self.maxsize(width=1920, height=1080)
backg = PhotoImage(file="img/trineside.png")
backg1 = PhotoImage(file="img/prueba4.png")
def delete_pages():
for frame in main_frame.winfo_children():
frame.destroy()
menu_frame = tk.Frame(self, bg="#124e6b", highlightbackground="black", highlightthickness=1)
menu_frame.pack(side=tk.LEFT)
menu_frame.pack_propagate(False)
menu_frame.configure(width=195, height=1020)
background_menuframe= Label(menu_frame, image=backg)
background_menuframe.place(x=0, y=0, relwidth=1, relheight=1)
inicio_btn = tk.Button(menu_frame, text="Inicio", font=("Bold", 18), fg="white", bd=0, bg="#124e6b", padx=56, activebackground='#124e6b', command=lambda: delete_pages() and InicioPage(main_frame))
inicio_btn.place(x=10, y=100)
page1_indicate = tk.Label(menu_frame, text="", bg="#124e6b")
page1_indicate.place(x=3, y=100, width=5, height=43)
#########################################################
clientes_btn = tk.Button(menu_frame, text="Page2", font=("Bold", 18), fg="white", bd=0, bg="#124e6b",padx=40, command=lambda: indicate(page2_indicate, page_2))
clientes_btn.place(x=10, y=150)
page2_indicate = tk.Label(menu_frame, text="", bg="#124e6b")
page2_indicate.place(x=3, y=150, width=5, height=43)
#########################################################
main_frame = tk.Frame(self, highlightbackground="black", highlightthickness=1)
background_mainframe= Label(main_frame, image=backg1)
background_mainframe.place(x=0, y=0, relwidth=1, relheight=1)
main_frame.pack(side=tk.LEFT)
main_frame.pack_propagate(False)
main_frame.configure(height=1020, width=1750)
lb = tk.Label(main_frame, text="Try", font=("bold", 50))
lb.pack(pady=100)
frame_inicio.py
from tkinter import *
import tkinter as tk
class InicioPage:
def __init__(self, main_frame):
self.frame = tk.Frame(main_frame)
backg1 = PhotoImage(file="img/prueba4.png")
background_mainframe= Label(main_frame, image=backg1)
background_mainframe.place(x=0, y=0, relwidth=1, relheight=1)
inicio_frame = tk.Frame(main_frame)
titulo_principal = tk.Label(main_frame,text="INICIO", font=("Bold", 15), bg="#031f3f", fg="white", height="2")
titulo_principal.pack(fill=tk.X)
inicio_frame.pack(pady=80)
#frames
f1_frame = tk.Frame(self.frame, bg="yellow", width=600, height=150)
f1_frame.pack()
f2_frame = tk.Frame(self.frame, width=500, height=400)
f2_frame.pack()
box1 = tk.Frame(f2_frame, height=20,width=250)
box1.grid(row=0, column=0)
box2 = tk.Frame(f2_frame, height=20,width=250)
box2.grid(row=0, column=1)
btn_logs = Button(box1,text="Abrir Logs",width=18)
btn_logs.pack(pady=20,padx=80)
btn_informes = Button(box2,text="Abrir Informes", width=18)
btn_informes.pack(pady=20,padx=80)
You aren't instantiating the class InicioPage anywhere I can see. You'll need to create an instance of InicioPage with the desired parent like so:
from frame_inicio import InicioPage
... # other code has been omitted for brevity
# FYI, widgets that are defined within a class should be prefixed with 'self.'
# e.g.: 'self.main_frame = tk.Frame', 'self.main_frame.pack()', etc.
main_frame.pack(side=tk.LEFT)
self.start_page = InicioPage(main_frame) # instantiate the class object to use it
Note that for the expression delete_pages() and InicioPage(main_frame), InicioPage(main_frame) will never be executed because delete_pages() returns None which is evaluated as False in the expression.
Either return True from delete_pages() or change and to or in the expression.
Got from #JRiggles's example.
In line 49 change this:
clientes_btn = tk.Button(menu_frame, text="Page2", font=("Bold", 18), fg="white", bd=0, bg="#124e6b",padx=40, command=lambda: InicioPage(page2_indicate))
to:
clientes_btn = tk.Button(menu_frame, text="Page2", font=("Bold", 18), fg="white", bd=0, bg="#124e6b",padx=40, command=lambda: InicioPage(main_frame))
frame_inicio.py.
Add this self.frame.mainloop() to bottom
Screenshot:
Screenshot when pressed page 2 button:
Related
This is a part of code from my school project.
from tkinter import *
from tkinter.font import Font
class student_window():
def __init__(self, master):
self.student_win = master
#window = Toplevel(self.master)
self.student_win.geometry("1280x720")
self.header1Font = Font(family='Helvetica', size=20)
self.optionFont = Font(family='Sans Serrif', size=20)
self.student_win.focus()
self.show_window()
def show_window(self):
print("ookk")
self.student_win.title("Student Window")
self.option_frame = Frame(self.student_win, width=200, height=720)
lbl_header = Label(self.option_frame,text="EXAMINATION", font=self.header1Font, fg='white', bg='#172D44').grid(row=0,column=0, sticky=NSEW)
lbl_welcome = Label(self.option_frame, text="Welcome,", fg='#E9F1F7', bg='#2A3F54').grid(row=1,column=0)
lbl_username = Label(self.option_frame, text="Username", fg='white', bg='#2A3F54').grid(row=2,column=0)
lbl_header2 = Label(self.option_frame, text="STUDENT CORNER", fg='white', bg='#2A3F54').grid(row=3, column=0)
self.btn_tests = Button(self.option_frame, text="Attempt Exam", fg='#E9F1F7', bg='#35495D', relief=FLAT)
self.btn_tests.grid(row=4,column=0, sticky=NSEW)
self.btn_attempts = Button(self.option_frame, text="Attempts", fg='#E9F1F7', bg='#2A3F54', relief=FLAT)
self.btn_attempts.grid(row=5, column=0, sticky=NSEW)
self.btn_result = Button(self.option_frame, text="Result", fg='#E9F1F7', bg='#2A3F54', relief=FLAT)
self.btn_result.grid(row=6, column=0, sticky=NSEW)
self.btn_goBack = Button(self.option_frame, text="Go Back", fg='#E9F1F7', bg='#2A3F54', relief=FLAT)
self.btn_goBack.grid(row=7, column=0, sticky=NSEW)
self.option_frame.configure(bg='#2A3F54')
self.option_frame.grid(row=0, column=0)
self.option_frame.grid_propagate(0)
self.main_frame = Frame(self.student_win, width=880, height=720)
self.main_result_frame = Frame(self.main_frame)
self.main_result_frame.grid(row=0,column=0)
self.attempts_frame = Frame(self.main_frame)
self.attempts_frame.grid(row=0, column=0)
self.test_frame = Frame(self.main_frame)
lbl_test = Label(self.test_frame, text="In test frame").pack()
self.test_frame.grid(row=0,column=0)
self.main_frame.grid(row=0,column=1)
self.main_frame.grid_propagate(0)
self.info_frame = Frame(self.student_win, width=200, height=720)
self.btn_username = Button(self.info_frame, text="Username", relief=FLAT)
self.btn_username.grid(row=0,column=0)
self.userInfo_frame = Frame(self.info_frame)
self.info_frame.grid(row=0, column=2)
self.info_frame.grid_propagate(0)
root = Tk()
student_window(root)
root.mainloop()
And it looks something like this.
The Student Panel for my project
The whole window is divided into three frames and want to expand each label and button of the left frame(self.option_frame) to fill it horizontally. I tried doing sticky=EW and sticky=NSEW but still some space is left. How do I fix that?
You need to call self.option_frame.columnconfigure(0, weight=1) to make column 0 to use all the available horizontal space.
I was just trying some things and what I have found to be working is to make the label width bigger than than the frame then anchoring the text to the left.
Very simple, don't be impressed by the size of the code.
I want to do something very simple (well, not for me, since I'm asking for help here) put the location of the open file in the red square on the screen:
Screen
import tkinter as tk
from tkinter.filedialog import askopenfilename
from tkinter import messagebox
def OpenFile_AntiDuplicate():
global antiduplicate_file
mainframe = tk.Frame(bg='#1c2028')
antiduplicate_file = askopenfilename(initialdir="/",
filetypes =(("Text file", "*.txt"),("All files","*.*")),
title = "Open text file"
)
fichier_dir = tk.Label(mainframe, text=antiduplicate_file).pack()
try:
with open(antiduplicate_file,'r') as UseFile:
print(antiduplicate_file)
except:
print("Non-existent file")
def RUN_AntiDuplicate():
try:
with open(antiduplicate_file,'r') as UseFile:
print(antiduplicate_file)
except:
error1 = tk.messagebox.showerror("ERROR", "No files exist!")
#----------------------------------------------------------
class HoverButton(tk.Button):
def __init__(self, master, **kw):
tk.Button.__init__(self,master=master,**kw)
self.defaultBackground = self["background"]
self.bind("<Enter>", self.on_enter)
self.bind("<Leave>", self.on_leave)
def on_enter(self, e):
self['background'] = self['activebackground']
def on_leave(self, e):
self['background'] = self.defaultBackground
#----------------------------------------------------------
def Anti_Duplicate():
mainframe = tk.Frame(bg='#1c2028')
mainframe.grid(row=0, column=0, sticky='nsew')
bouton_1 = HoverButton(mainframe, font=("Arial", 10), text="Back",
background='#000000', fg='white', borderwidth=2,
activebackground='#202124', activeforeground='#CF3411',
relief='ridge', command=mainframe.destroy)
bouton_1.place(x=520, y=300)
open_button = HoverButton(mainframe, font=("Arial", 10), text="Open File..",
background='#000000', fg='white', borderwidth=2,
activebackground='#202124', activeforeground='#1195cf',
relief='ridge', command = OpenFile_AntiDuplicate)
open_button.place(x=284.3, y=200, anchor='n')
run_button = HoverButton(mainframe, font=("Arial", 20), text="RUN",
background='#000000', fg='white', borderwidth=2,
activebackground='#202124', activeforeground='#11CF6D',
relief='ridge', command = RUN_AntiDuplicate)
run_button.place(x=50, y=330, anchor='s')
bouton_2 = tk.Button(mainframe, font=("Arial", 10),
text="The purpose of this tool is to remove duplicate lines from a text file.",
background='#202124', fg='#1195cf', borderwidth=2,
activebackground= '#202124', activeforeground='#1195cf', relief='sunken')
bouton_2.place(relx=.5, y=50, anchor='n')
bouton_1 = tk.Button(mainframe, font=("Arial", 15), text="Anti-Duplicate",
background='#202124', fg='#1195cf', borderwidth=2,
activebackground='#202124', activeforeground='#1195cf', relief='sunken')
bouton_1.pack(side= "top", padx= 5, pady=5, ipadx= 30, anchor="n")
#----------------------------------------------------------
def main_menu():
root = tk.Tk()
screenn_x = int(root.winfo_screenwidth())
root.config(background='#1c2028')
screenn_y = int(root.winfo_screenheight())
root.title("ComboKit v0.0.1")
root.minsize(570, 340)
root.resizable(0,0)
windowss_x = 570
windowss_y = 340
possX = (screenn_x // 2) - (windowss_x // 2)
possY = (screenn_y // 2) - (windowss_y // 2)
geoo = "{}x{}+{}+{}".format(windowss_x, windowss_y, possX, possY)
root.geometry(geoo)
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
mainframe = tk.Frame(root, bg='#1c2028')
mainframe.grid(row=0, column=0, sticky='n')
main_fusion_bouton = HoverButton(mainframe, font=("Arial", 15), text="Fusion",
background='#000000', fg='white', borderwidth=2,
activebackground='#202124', activeforeground='#1195cf',
relief='ridge', command=None)
main_fusion_bouton.pack(side= "left", padx= 5, pady=5, ipadx= 10, anchor="n")
main_antiduplicate_bouton = HoverButton(mainframe, font=("Arial", 15), text="Anti-Duplicate",
background='#000000', fg='white', borderwidth=2,
activebackground='#202124', activeforeground='#1195cf',
relief='ridge', command=Anti_Duplicate)
main_antiduplicate_bouton.pack(side= "left", padx= 5, pady=5, ipadx= 30)
main_split_button = HoverButton(mainframe, font=("Arial", 15), text="Split",
background='#000000', fg='white', borderwidth=2,
activebackground='#202124', activeforeground='#1195cf',
relief='ridge', command=None)
main_split_button.pack(side= "left", padx= 5, pady=5, ipadx= 19, anchor="n")
root.mainloop()
main_menu()
So here's my code allows you to use 3 tools:
"Split" / "Anti-Duplicate" / "Merge"
At the moment I'm working on the "Anti-Duplicate" so it's on this Frame() where the text should be displayed.
I've already done everything, even the button to open the file explorer, but for the moment the location of the file is only displayed in the cmd.
Thank you very much!
The location of the file does not show up because you created a new frame to hold the label fichier_dir inside OpenFile_AntiDuplicate() and you did not call any layout function on the frame, so the frame will not be shown.
Better create the label fichier_dir inside Anti_Duplicate() and pass it to OpenFile_AntiDuplicate() function:
def Anti_Duplicate():
...
fichier_dir = tk.Label(mainframe, bg='#1c2028', fg='white')
fichier_dir.place(relx=0.5, y=170, anchor='n')
open_button = HoverButton(mainframe, font=("Arial", 10), text="Open File..",
background='#000000', fg='white', borderwidth=2,
activebackground='#202124', activeforeground='#1195cf',
relief='ridge', command = lambda: OpenFile_AntiDuplicate(fichier_dir))
...
And update OpenFile_AntiDuplicate(...):
def OpenFile_AntiDuplicate(fichier_dir):
global antiduplicate_file
antiduplicate_file = askopenfilename(initialdir="/",
filetypes =(("Text file", "*.txt"),("All files","*.*")),
title = "Open text file"
)
fichier_dir['text'] = antiduplicate_file
...
Im trying to make a tkinter GUI with an alarm clock and weather. My alarm clock is not working for some reason. I "borrowed" the code from another person and it works on his/her program for some reason but not mine.
I haven't tried anything because im very new to python and coding in general.
import tkinter as tk
from tkinter import *
from tkinter.ttk import *
import os
import time
from time import strftime
from datetime import date
today = date.today()
HEIGHT = 500
WIDTH = 500
def test_function(entry):
label3 = tk.Label(lower_frame, bg='white',font=('Courier',15), text=entry, anchor='nw', justify='left', bd=4)
label3.place(relwidth=1, relheight=1)
root = tk.Tk()
def quit_function():
root.destroy()
def SubmitButton():
AlarmTime= alarm_entry.get()
CurrentTime= time.strftime("%H:%M")
while AlarmTime != CurrentTime:
CurrentTime = time.strftime("%H:%M")
time.sleep(1)
if AlarmTime == CurrentTime:
label3 = tk.Label(lower_frame, bg='white',font=('Courier',15), text="Perkele", anchor='nw', justify='left', bd=4)
canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH)
canvas.pack()
background_image = tk.PhotoImage(file='landscape.png')
bg_label = tk.Label(root, image=background_image)
bg_label.place(x=0, y=0, relwidth=1, relheight=1)
frame = tk.Frame(root, bg='#08AEF6', bd=5)
frame.place(relx=0.5, rely=0.125, relwidth=0.75, relheight=0.1, anchor='n')
entry = tk.Entry(frame, font=40)
entry.place(relwidth=0.65, relheight=1)
button = tk.Button(frame, font=40, text="Get Weather", bg='gray', fg='black', command=lambda: test_function(entry.get()))
button.place(relx=0.7, relwidth=0.3, relheight=1)
lower_frame = tk.Frame(root, bg='#08AEF6', bd=10)
lower_frame.place(relx=0.5, rely=0.25, relwidth=0.75, relheight=0.6, anchor='n')
up_frame = tk.Frame(root, bg='#08AEF6', bd=5)
up_frame.place(relx=0.675, rely=0, relwidth=0.4, relheight=0.1, anchor='n')
alarm_button = tk.Button(up_frame, text="Set alarm time", bg='gray', fg='black', font=40, command=SubmitButton)
alarm_button.place(relx=0.7, rely=0.5, relwidth=0.3, relheight=0.45)
label3 = tk.Label(lower_frame, bg='white')
label3.place(relwidth=1, relheight=1)
label = tk.Label(up_frame, bg='white')
label.place(relx=0, relwidth=0.695, relheight=0.5)
date1 = tk.Label(up_frame, bg='white', text=today, font=40)
date1.place(relx=0, rely=0.5, relwidth=0.695, relheight=0.5)
quit_frame = tk.Frame(root, bg='#08AEF6', bd=5)
quit_frame.place(relx=0, rely=0, relwidth=0.1, relheight=0.1)
quit_button = tk.Button(quit_frame, command=quit_function, text="Quit")
quit_button.place(relwidth=1, relheight=1)
alarm_entry = tk.Entry(up_frame, font=40)
alarm_entry.insert(3, "esimerkiksi - 15:45")
alarm_entry.place(relx=0.7, rely=0, relwidth=0.3, relheight=0.45)
# label2 = tk.Label(lower_frame, bg='white')
root.overrideredirect(True)
root.geometry("{0}x{1}+0+0".format(root.winfo_screenwidth(), root.winfo_screenheight()))
root.focus_set()
def time():
string = strftime('%H:%M:%S')
label.config(text = string, font='40')
label.after(1000, time)
time()
It gives me this error in line 33.
AttributeError: 'function' object has no attribute 'strftime'
I have written this code in python 2.7 and i have used "pack_propagate" in this code. First time "pack_propagate" works fine but when i click on the button 1, "pack_propagate" doesn't work. can anyone tell me the reason?
from tkinter import *
root = Tk()
root.title("pack_forget check")
tk_window_width = 500
tk_window_height = 300
screen_width = root.winfo_screenwidth() # width of the screen
screen_height = root.winfo_screenheight() # height of the screen
x = (screen_width/2) - (tk_window_width/2)
y = (screen_height/2) - (tk_window_height/2)
root.geometry('%dx%d+%d+%d' %(tk_window_width, tk_window_height, x, y))
frame1 = Frame(root, bg="red", height=250, width=250)
frame2 = Frame(root, bg="green", height=250, width=250)
def first():
frame1.pack(side=TOP, padx=20, pady=20)
frame1.pack_propagate(0)
frame2.pack_forget()
def second():
frame2.pack(side=TOP, padx=20, pady=20)
frame2.pack_propagate(0)
frame1.pack_forget()
label1 = Label(frame1, text="Frame 1")
label1.pack(side="top")
button1 = Button(frame1, text="button 1", command=second, width=10)
button1.pack(side="bottom")
label2 = Label(frame2, text="Frame 2")
label2.pack(side="top")
button2 = Button(frame2, text="button 2", command=first, width=10)
button2.pack(side="bottom")
frame1.pack(side=TOP, padx=20, pady=20)
frame1.pack_propagate(0)
root.mainloop()
Add this before the mainloop(), it seems to solve the problem. Honestly, I am unsure how it works, but looks like it does. I saw you did that with frame1 and I was like: hey, why not frame2? :D
frame2.pack(side=TOP, padx=20, pady=20)
frame2.pack_propagate(0)
root.mainloop()
I am working on a program where there is a scrollable frame that will be containing a large quantity of items. But with my app it does not render all of them. Can someone possibly tell me why? And how I can fix it?
Code:
#700x650
from Tkinter import *
import ttk
class itemLoad:
def __init__(self):
pass
def item(self):
items = "Video File,Image File,None,King King"
return items
class App(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.pack(fill=BOTH)
self.loadItem = itemLoad()
self.one = None
self.create_widgets()
self.loadItems()
def create_widgets(self):
self.mainFrame = Frame(self, width=700, height=650)
self.mainFrame.pack_propagate(False)
self.mainFrame.pack()
self.menu = Frame(self.mainFrame, width=150, height=650, bg="Gray92")
self.menu.pack_propagate(False)
self.menu.pack(side=LEFT)
self.itemMenu = Frame(self.mainFrame, width=550, height=650)
self.itemMenu.pack_propagate(False)
self.itemMenu.pack(side=LEFT)
self.vScroller = ttk.Scrollbar(self.itemMenu, orient=VERTICAL)
self.vScroller.pack(side=RIGHT, fill=Y)
self.canvas = Canvas(self.itemMenu, bd=0, width=534, highlightthickness=0, yscrollcommand=self.vScroller.set)
self.canvas.pack_propagate(False)
self.canvas.pack(side=LEFT, fill=BOTH)
self.vScroller.config(command=self.canvas.yview)
self.innerFrame = Frame(self.canvas, width=550, height=650, bg="Pink")
self.canvas.create_window(0, 0, window=self.innerFrame, anchor=NW)
def update(event):
self.canvas.config(scrollregion=self.canvas.bbox("all"))
self.innerFrame.bind("<Configure>", update)
self.spacer = Frame(self.mainFrame, bg="Gray")
self.spacer.pack(side=LEFT, fill=Y)
frame = Frame(self.menu, bg="Gray92")
frame.pack(side=TOP, fill=X)
high = Frame(frame, bg="Gray92", width=10)
high.pack(side=LEFT, fill=Y)
self.bu1 = Label(frame, font=("Calibri", 14), text=" Main Folder", width=12, anchor=W, bg="Gray92")
self.bu1.pack(side=LEFT, fill=X, ipadx=10, ipady=10)
frame2 = Frame(self.menu, bg="Gray92")
frame2.pack(side=TOP, fill=X)
high2 = Frame(frame2, bg="Gray92", width=10)
high2.pack(side=LEFT, fill=Y)
self.bu2 = Label(frame2, font=("Calibri", 14), text=" Favorited", width=12, anchor=W, bg="Gray92")
self.bu2.pack(side=LEFT, fill=X, ipadx=10, ipady=10)
frame3 = Frame(self.menu, bg="Gray92")
frame3.pack(side=TOP, fill=X)
high3 = Frame(frame3, bg="Gray92", width=10)
high3.pack(side=LEFT, fill=Y)
self.bu3 = Label(frame3, font=("Calibri", 14), text=" Trash Can", width=12, anchor=W, bg="Gray92")
self.bu3.pack(side=LEFT, fill=X, ipadx=10, ipady=10)
frame4 = Frame(self.menu, bg="Gray92")
frame4.pack(side=BOTTOM, fill=X)
high4 = Frame(frame4, bg="Gray92", width=10)
high4.pack(side=LEFT, fill=Y)
self.bu4 = Label(frame4, font=("Calibri", 14), text=" Log Out", width=12, anchor=W, bg="Gray92")
self.bu4.pack(side=LEFT, fill=X, ipadx=10, ipady=10)
def hover(event):
widg = event.widget
items = widg.winfo_children()
if items[1].cget("text") == self.one:
pass
else:
items[0].config(bg="Gray85")
items[1].config(bg="Gray85")
def unHover(event):
widg = event.widget
text = None
items = widg.winfo_children()
if items[1].cget("text") == self.one:
pass
else:
items[0].config(bg="Gray92")
items[1].config(bg="Gray92")
def clicked(event):
widg = event.widget
par = widg.winfo_parent()
par = self.menu._nametowidget(par)
for item in self.menu.winfo_children():
items = item.winfo_children()
items[0].config(bg="Gray92")
for item in par.winfo_children():
try:
self.one = item.cget("text")
except:
item.config(bg="lightBlue")
frame.bind("<Enter>", hover)
frame2.bind("<Enter>", hover)
frame3.bind("<Enter>", hover)
frame4.bind("<Enter>", hover)
frame.bind("<Leave>", unHover)
frame2.bind("<Leave>", unHover)
frame3.bind("<Leave>", unHover)
frame4.bind("<Leave>", unHover)
high.bind("<Button-1>", clicked)
self.bu1.bind("<Button-1>", clicked)
high2.bind("<Button-1>", clicked)
self.bu2.bind("<Button-1>", clicked)
high3.bind("<Button-1>", clicked)
self.bu3.bind("<Button-1>", clicked)
high4.bind("<Button-1>", clicked)
self.bu4.bind("<Button-1>", clicked)
def loadItems(self):
theItems = self.loadItem.item()
for i in range(0, 500):
none = Frame(self.innerFrame, width=200, height=500, bg="red")
none.pack_propagate(False)
none.pack(side=TOP, padx=10, pady=10)
let = Label(none, text=i)
let.pack(side=TOP)
root = Tk()
root.geometry("700x650")
root.resizable(0,0)
app = App(root)
root.mainloop()
I think you're exceeding the limits of the tkinter canvas. The frame you're trying to scroll is 250,000 pixels tall. I doubt the canvas can handle that.
When I make all of your inner widgets considerably smaller your code works fine.