ahmad_20

main.py

Sep 20th, 2020
865
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.80 KB | None | 0 0
  1. from tkinter import font
  2. from tkcalendar import Calendar, DateEntry
  3. import tkinter as tk
  4.  
  5. # set font options for button
  6. FirstFont =('Helvetica', 20)
  7.  
  8. # create class for initialized gui
  9. class app(tk.Tk):
  10.     def __init__(self, *args, **kwargs):
  11.         tk.Tk.__init__(self, *args, **kwargs)
  12.         # create windows container or frame main
  13.         frm_main = tk.Frame(self)
  14.         frm_main.pack(side = "top", expand = True)
  15.         frm_main.grid_rowconfigure(0, weight = 1)
  16.         frm_main.grid_columnconfigure(0, weight = 1)
  17.  
  18.         # initiaze frame to empty array
  19.         self.frames = {}
  20.  
  21.         # create different window iteration
  22.         for F in (mainpage, insert_data, export_data):
  23.             frame = F(frm_main, self) # need explanation in cheat sheet
  24.             # initiaze first window
  25.             self.frames[F] = frame
  26.             frame.grid(row = 0, column = 0, sticky ="nsew")
  27.         self.show_frame(mainpage)
  28.    
  29.     # to display the current frame passed as
  30.     # parameter
  31.     def show_frame(self, cont):
  32.         frame = self.frames[cont]
  33.         frame.tkraise()
  34.  
  35. # first window frame startpage
  36.  
  37. class mainpage(tk.Frame):
  38.     def __init__(self, parent, controller):
  39.         tk.Frame.__init__(self, parent)
  40.        
  41.         # button for main page
  42.         btn_export = tk.Button(self, text ="Export Data", font = FirstFont, command = lambda : controller.show_frame(export_data))
  43.         btn_insert = tk.Button(self, text ="Insert Data", font = FirstFont, command = lambda : controller.show_frame(insert_data))
  44.        
  45.         # putting the grid in its place by using
  46.         # grid
  47.         #btn_insert.grid(row = 0, padx = 10, pady = 10, sticky ="ew")
  48.         #btn_export.grid(row = 1, padx = 10, pady = 10, sticky ="ew")
  49.         btn_insert.pack(fill='both', expand=True)
  50.         btn_export.pack(side='bottom', fill='both', expand=True)
  51.  
  52.        
  53.  
  54. class insert_data(tk.Frame):
  55.     def __init__(self, parent, controller):
  56.         tk.Frame.__init__(self, parent)
  57.  
  58.         # create calender dropdown menu
  59.         cal_input = DateEntry(
  60.             self,
  61.             width = 12,
  62.             borderwidth = 2,
  63.             year = 2020,
  64.             background = 'blue'
  65.         )
  66.  
  67.         # create dropdown menu
  68.         variable = tk.StringVar(self)
  69.         variable.set('Weekdays')
  70.         dropdown_date = tk.OptionMenu(
  71.             self,
  72.             variable,
  73.             'Weekend',
  74.             'Weekdays',
  75.         )
  76.  
  77.         # create input widget
  78.         ent_activity = tk.Entry(
  79.             self,
  80.             width = 30
  81.         )
  82.  
  83.         # create button for 2nd page
  84.         btn_data = tk.Button(
  85.             self,
  86.             text = 'Add data',
  87.             width = 25
  88.  
  89.         )
  90.  
  91.         # create button for return to main menu
  92.         btn_back = tk.Button(
  93.             self,
  94.             text = 'Back',
  95.             width = 25,
  96.             background = 'red',
  97.             command = lambda : controller.show_frame(mainpage)
  98.         )
  99.  
  100.         # put widget on grid
  101.         btn_data.grid(row = 3, column = 1, padx = 10, pady = 10)
  102.         btn_back.grid(row = 4, column = 1, padx = 10, pady = 5)
  103.         cal_input.grid(row = 1, column = 1, padx = 10, pady = 5, sticky = 'ew')
  104.         dropdown_date.grid(row = 2, column = 1, padx = 10, pady = 5, sticky ='ew')
  105.         ent_activity.grid(row = 0, column = 1, padx = 10, pady = 5)
  106.  
  107. class export_data(tk.Frame):
  108.     def __init__(self, parent, controller):
  109.         tk.Frame.__init__(self, parent)
  110.  
  111.         # create calender dropdown menu
  112.         cal_export = DateEntry(
  113.             self,
  114.             width = 12,
  115.             borderwidth = 2,
  116.             year = 2020,
  117.             background = 'blue'
  118.         )
  119.  
  120.         # export button
  121.         btn_export_data = tk.Button(
  122.             self,
  123.             text = 'Export Data',
  124.             width = 25,
  125.            
  126.         )
  127.  
  128.         # back button to main menu
  129.         btn_back = tk.Button(
  130.             self,
  131.             text = 'Back',
  132.             width = 25,
  133.             background = 'red',
  134.             command = lambda : controller.show_frame(mainpage)
  135.         )
  136.  
  137.    
  138.  
  139.         # put widget on grid
  140.         cal_export.grid(row = 0, column = 0, padx = 10, pady = 5, sticky = 'ew')
  141.         btn_export_data.grid(row = 1, padx = 10, pady = 15)
  142.         btn_back.grid(row = 2, padx = 10, pady = 10)
  143.  
  144.        
  145.  
  146. # Driver Code
  147. app1 = app()
  148. app1.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment