Python - How to make a QR code image with Python

This script use Tkinter, Image and pyqrcode to make an image of the text entered in the text field.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/python

from Tkinter import *
import Image
import pyqrcode

''' Functions '''
def makeQRCode():
    qr_data = txt_Input.get()
    url = pyqrcode.create(qr_data)
    url.png('url.png', scale = 8)
    img = Image.open('url.png')
    img.show()

    print (qr_data)

def clearInputField():
    txt_Input.delete(0, 'end')

''' This will make the main window '''
window = Tk()
window.title("QR Code generator")
window.geometry('250x130')

''' This will place labels, entries and buttons '''
lbl_Header = Label(window, text="Enter source text to make QR code from")
lbl_Header.grid(column=0, row=0)

txt_Input = Entry(window, width=20)
txt_Input.grid(column=0, row=1)

btn_MakeQRCode = Button(window, text="Make QR code", command=makeQRCode)
btn_MakeQRCode.grid(column=0, row=2)

btn_Clear = Button(window, text="Clear", command=clearInputField)
btn_Clear.grid(column=0, row=3)

btn_Quit = Button(window, text="Quit", command=window.quit)
btn_Quit.grid(column=0, row=4)

''' Run the mainloop '''
window.mainloop()

blogroll

social