You are on page 1of 7

import tkinter as tk

from tkinter import *

from tkinter import ttk, filedialog

from tkcalendar import DateEntry

from PIL import Image, ImageTk

from tkinter import messagebox

import re

import mysql.connector as ms

from datetime import datetime

import base64

import sys

import subprocess

import os

import io

import mysql.connector

from PIL import Image, ImageTk

import base64

#import tkinter.messagebox

from datetime import datetime, timedelta


class MainApplicationForm(tk.Tk):

def __init__(self):

print("MainApplicationForm constructor is called")

super().__init__()

self.title("Main Form")

self.geometry("800x500")

self.reportno=0

# Create a main container frame to hold all other frames

self.main_frame = tk.Frame(self)

self.main_frame.pack(fill=tk.BOTH, expand=True)

# Create a horizontal scrollbar and connect it to the canvas

self.x_scrollbar = ttk.Scrollbar(self.main_frame, orient=tk.HORIZONTAL)

self.canvas = tk.Canvas(self.main_frame, xscrollcommand=self.x_scrollbar.set)

self.x_scrollbar.config(command=self.canvas.xview)

# Create a vertical scrollbar and connect it to the canvas

self.y_scrollbar = ttk.Scrollbar(self.main_frame, orient=tk.VERTICAL)

self.canvas.config(yscrollcommand=self.y_scrollbar.set)

self.y_scrollbar.config(command=self.canvas.yview)

# Create a frame to hold all components

self.container = tk.Frame(self.canvas, borderwidth=1, relief=tk.RIDGE)

self.canvas.create_window((0, 0), window=self.container, anchor=tk.NW)


# Add the scrollbars to the canvas

self.canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)

self.x_scrollbar.pack(side=tk.BOTTOM, fill=tk.X)

self.y_scrollbar.pack(side=tk.RIGHT, fill=tk.Y)

# Bind the container frame resize to configure the canvas scroll region

self.container.bind("<Configure>", self.configure_canvas_scroll_region)

def initUI(self):

# Create a menu bar

menubar = tk.Menu(self)

# Create a File menu and add items to it

menu1 = tk.Menu(menubar, tearoff=0)

menu1.add_command(label="Student Registration",
command=self.create_personal_info_frame)

menu1.add_command(label="Generate Student form", command=self.search_form)

menu1.add_separator()
menu1.add_command(label="Exit",command=self.quit_app)

# Add the File menu to the menu bar

menubar.add_cascade(label="Student Page", menu=menu1)

# Create a File menu and add items to it

"""menu2 = tk.Menu(menubar, tearoff=0)

menu2.add_command(label="Book Online Airticket...",


command=self.create_personal_info_frame)

menu2.add_command(label="Generate Air Ticket...", command=self.search_form)

menu2.add_separator()

menu2.add_command(label="Exit",command=self.quit_app)

# Add the File menu to the menu bar

menubar.add_cascade(label="Customer Page...", menu=menu2)"""

# Attach the menu bar to the main window

self.config(menu=menubar)

def quit_app(self):

sys.exit()

def create_group_frame(self, parent, bg_color):

frame = tk.Frame(parent, borderwidth=1, relief=tk.RIDGE, bg=bg_color)

return frame

def configure_canvas_scroll_region(self, event):

self.canvas.configure(scrollregion=self.canvas.bbox("all"))
# write code here for giving warning message , if the browsed image size is too lang than Mysql-
blob datatype size

class studentform2(MainApplicationForm):

def __init__(self):

print("studentform2 constructor is called")

super().__init__()

print("Constructor is called...")

#self.c_id = tk.StringVar()

def search_form(self):

print("hi ")

class studentform1(studentform2):

def __init__(self):

print("studentform1 constructor is called")

super().__init__()

self.title("Student Application Form")


self.geometry("800x500")

self.initUI() # Fn callingfor menu

#self.reportno=0

def upload_photo(self):

file_path = filedialog.askopenfilename(filetypes=[("Image Files", "*.png;*.jpg;*.jpeg;*.gif")])

if file_path:

with open(file_path, "rb") as file:

self.image_data = file.read()

# Check image size against MySQL BLOB size (in bytes)

mysql_blob_size_limit = 65535 # MySQL BLOB size limit in bytes

if len(self.image_data) > mysql_blob_size_limit:

warning_message = "Warning: Selected image size is too large for MySQL BLOB datatype."

messagebox.showinfo("Flight", str(warning_message))

#self.show_warning(warning_message)

return

# Resize the image if needed

image = Image.open(io.BytesIO(self.image_data))

image = image.resize((150, 150), Image.LANCZOS)

self.photo = ImageTk.PhotoImage(image)

self.photo_label.config(image=self.photo)

self.photo_label.image = self.photo

else:
self.photo_label.config(image="")

self.photo_label.image = None

def create_personal_info_frame(self):

print("hi")

if __name__ == "__main__":

app = studentform1()

app.mainloop()

You might also like