'How to put buttons and contents in separate frames in tkinter
I am trying to create two different frames and navigate through them using buttons but I am not succeeding. I want to put buttons aligned vertically on a separate frame on the left and different departments opening by click of a button on the right frame. Kindly help. I will appreciate it.
from tkinter import*
root= Tk()
root.title("DEPARTMENTAL MANAGEMENT SYSTEM")
root.geometry('1200x800')
#=========================frames====================
leftframe=Frame(root, bg="blue")
leftframe.grid()
HRrightframe=Frame(root, bg="green")
HRrightframe.grid()
Schainrightframe=Frame(root, bg="green")
Schainrightframe.grid()
#=========================functions for switching the frames========
def change_to_HRrightframe():
HRrightframe.grid()
Schainrightframe.grid_forget()
def change_to_Schainrightframe():
Schainrightframe.grid()
HRrightframe.grid_forget()
#=====================Add heading logo in the frames======
labelHR=Label(HRrightframe, text="HR DEPARTMENT")
labelHR.grid()
labelSchain=Label(Schainrightframe, text="SUPPLY CHAIN DEPARTMENT")
labelSchain.grid()
#===============================add button to switch between frames=====
btn1=Button(leftframe, text="HR", command=change_to_HRrightframe, width=20)
btn1.grid(row=0,column=0)
btn2=Button(leftframe, text="SUPPLY CHAIN", command=change_to_Schainrightframe, width=20)
btn2.grid(row=1,column=0)
root.mainloop()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
