0% found this document useful (0 votes)
5 views9 pages

QR Code Generator

The document describes a QR Code Generator desktop application developed for an Object-Oriented Programming course. It allows users to input custom text to generate and save QR codes using a simple graphical interface built with tkinter and the qrcode library. The application includes functionalities for generating QR codes, displaying them, and saving them as PNG files with user-defined filenames.

Uploaded by

arad82865
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views9 pages

QR Code Generator

The document describes a QR Code Generator desktop application developed for an Object-Oriented Programming course. It allows users to input custom text to generate and save QR codes using a simple graphical interface built with tkinter and the qrcode library. The application includes functionalities for generating QR codes, displaying them, and saving them as PNG files with user-defined filenames.

Uploaded by

arad82865
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

QR CODE

GENERATOR

ECE115.2-OBJECT ORIENTED PROGRAMMING FOR BSECE


(16NO)

Group members:

KURT LIWENCE RELUNIO

MATT JOSHUA ABOBO

DEAN JOSHUA ARAÑEZ


Description of the Project

​ A QR code (Quick Response code) is a type of two-dimensional barcode that


stores information, such as text, URLs, or other data, in a grid od black and white
squares. QR code can be scanned using a smartphone or a QR code reader, allowing
users to quickly access the stored information. They are commonly used for various
purposes, including marketing, product tracking, payment system and information
sharing, due to their ability to store large amounts of data in a small space and their
ease to use.

QR Code Generator a desktop application that enables users to generate and


save QR codes from custom text inputs through a simple graphical interface. Built with
tkinter, the tool offers a lightweight and responsive GUI for creating codes in real time.

Core Functionalities

●​ Accepts user input for date to encode.


●​ Generates a QR code using the qrcode library.
●​ Displays the QR code image dynamically within the interface.
●​ Allows saving the QR code as a PNG file with a custom filename.
Required Libraries to be Installed

●​ qrcode[pil] - QR Code Generation with Image Support


-​ [pil] means it installs the Pillow library, which is used to create and
manipulate images.
●​ tkinter - Graphical User Interface (GUI) toolkit, Python’s built-in library for creating
GUI applications.
-​ It allows you to build windows, buttons, labels, text inputs, and display
images.

To Install Required Libraries

To install the required libraries, write the following in the Python Terminal:

pip install qrcode[pil] tkinter

Source Code:

import qrcode

from PIL import ImageTk

import tkinter as tk

from tkinter import messagebox

class QRCodeApp:

​ def __init__(self, root):

​ # main window

​ self.root = root

​ self.root.title('QR Code Generator')


​ self.root.geometry('350x575')

​ self.root.configure(bg='#21252b')

​ # icon

​ self.root.iconphoto(False, tk.PhotoImage(file='icon.png'))

​ # label

​ self.label = tk.Label(root, text='Enter data to encode:', font=('Arial', 10),


fg='#e5e5e5', bg='#4584B6')

​ self.label.pack(pady=10, ipady=2.5, ipadx=5)

# allows you to input text

​ self.data_entry = tk.Entry(root, width=40, fg='#e5e5e5')

​ self.data_entry.pack(pady=5, ipady=2.5, ipadx=5)

​ self.data_entry.configure(bg='#333845', relief='flat')

​ # adds a button to generate the QR code

​ self.generate_btn = tk.Button(root, text='Generate QR Code',


command=self.generate)

​ self.generate_btn.pack(pady=10, ipady=1, ipadx=5)

self.generate_btn.configure(fg='#e5e5e5', bg='#955455', relief='flat')

​ # where the QR code will be displayed

​ self.qr_label = tk.Label(root)
​ self.qr_label.pack(pady=20)

​ self.qr_label.configure(bg='#21252b')

​ # adds a button to save the QR code

​ self.save_btn = tk.Button(root, text='Save QR Code', command=self.save_qr)

​ self.save_btn.pack(pady=10, ipady=1, ipadx=5)

​ self.save_btn.configure(fg='#e5e5e5', bg='#955455', relief='flat')

​ self.qr_img = None

​ self.last_data = None

​ self.confirm_save_btn = None

​ self.filename_entry = None

​ self.filename_label = None

​ self.root.mainloop()

​ def generate(self):

​ # gets user input

​ data = self.data_entry.get()

​ if not data:

​ messagebox.showwarning('Input Required', 'Please enter data to generate QR


code.')

​ return
​ if data == self.last_data:

self.save_btn.config(state=tk.NORMAL)

​ return

​ # creates & resizes the QR code for display

​ qr = qrcode.make(data)

​ qr = qr.resize((200, 200))

​ # stores and displays the image

​ self.qr_img = qr

​ qr_tk = ImageTk.PhotoImage(qr)

​ self.qr_label.config(image=qr_tk)

​ self.qr_label.image = qr_tk

​ # update the last input

​ self.last_data = data

​ # activates the save button when a new QR code is generated

​ self.save_btn.config(state=tk.NORMAL)

​ # Cleanup any previous filename input widgets ONLY if the data is new

​ self.cleanup_save_widgets()
​ def save_qr(self):

​ # if the QR code is not yet generated

​ if not self.qr_img:

​ messagebox.showwarning('No QR Code', 'Generate a QR code first.')

​ return

​ # If already shown, do nothing

​ if self.filename_entry:

​ return

​ # show filename label input

​ self.filename_label = tk.Label(self.root, text='Enter filename:', font=('Arial', 10),


fg='#e5e5e5', bg='#4584B6')

​ self.filename_label.pack(pady=10, ipady=2.5, ipadx=5)

​ # allows you to input the filename

​ self.filename_entry = tk.Entry(self.root, width=40, fg='#e5e5e5')

​ self.filename_entry.pack(pady=5, ipady=2.5, ipadx=5)

self.filename_entry.configure(bg='#333845', relief='flat')

​ # adds a confirm button

​ self.confirm_save_btn = tk.Button(self.root, text='Confirm Save',


command=self.confirm_save)
​ self.confirm_save_btn.pack(pady=10, ipady=1, ipadx=5)

self.confirm_save_btn.configure(fg='#e5e5e5', bg='#955455', relief='flat')

​ # Disable the button after clicking

​ self.save_btn.config(state=tk.DISABLED)

​ def confirm_save(self):

​ # gets the filename that was inputted & removes spaces

​ filename = self.filename_entry.get().strip()

​ # if there is no filename inputted

​ if not filename:

​ messagebox.showwarning('No Filename', 'Please enter a filename.')

​ return

​ try:

​ self.qr_img.save(f'{filename}.png')

​ messagebox.showinfo('Saved', f'QR code saved as "{filename}.png"')

​ # removes the widgets once the save is finished.

​ self.filename_entry.destroy()

​ self.confirm_save_btn.destroy()

​ self.filename_entry = None

​ self.confirm_save_btn = None
​ # checks for errors

​ except Exception as e:

​ messagebox.showerror('Save Error', f'Could not save file: {e}')

​ def cleanup_save_widgets(self):

​ # clean up filename input and confirm button

​ if self.filename_entry:

​ self.filename_entry.destroy()

​ if self.confirm_save_btn:

​ self.confirm_save_btn.destroy()

​ if self.filename_label:

​ self.filename_label.destroy()

​ # reset to none after cleanup

​ self.filename_entry = None

​ self.confirm_save_btn = None

​ self.filename_label = None

# runs the app

if _name_ == '_main_':

​ main_window = tk.Tk()

​ app = QRCodeApp(main_window)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy