-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
62 lines (47 loc) · 1.68 KB
/
app.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import tkinter as tk
from tkinter import Label
import qrcode
import random
import re
def load_words_from_file(filename):
try:
with open(filename, 'r') as file:
words = [line.strip() for line in file if line.strip()]
return words
except FileNotFoundError:
print(f"Error: The file {filename} was not found.")
return []
def generate_random_word(words):
random_word = random.choice(words)
cleaned_word = re.sub(r'\s*\(.*?\)', '', random_word).strip()
return cleaned_word
def generate_random_sentence(words, num_words=5):
selected_words = [generate_random_word(words) for _ in range(num_words)]
sentence = ' '.join(selected_words) + '.'
return sentence.capitalize()
def create_google_search_url(sentence):
return f"https://www.google.com/search?q={sentence.replace(' ', '+')}"
def create_qr_code(url):
qr = qrcode.QRCode(version=1, box_size=10, border=5)
qr.add_data(url)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
img.save("qr_code.png")
def show_qr_code_window(url):
root = tk.Tk()
root.title("QR Code Generator")
label = Label(root, text="Scan it!")
label.pack(pady=10)
qr_image = tk.PhotoImage(file="qr_code.png")
qr_label = Label(root, image=qr_image)
qr_label.pack(pady=10)
qr_label.image = qr_image
root.mainloop()
def main():
words = load_words_from_file('words.txt')
random_sentence = generate_random_sentence(words, num_words=5)
search_url = create_google_search_url(random_sentence)
create_qr_code(search_url)
show_qr_code_window(search_url)
if __name__ == "__main__":
main()