-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
62 lines (48 loc) · 1.74 KB
/
main.py
File metadata and controls
62 lines (48 loc) · 1.74 KB
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 docxtpl as docx
import tkinter as tk
import sqlite3
import os
from tkinter import ttk
from tkinter import scrolledtext
## titel, best_person, text
class database:
def __init__(self) -> None:
self.con = sqlite3.connect("database.db")
self.cur = self.con.cursor()
def create_table(self):
self.cur.execute("CREATE TABLE movie(title, year, score)")
def retrieve_names(self):
res = self.cur.execute("SELECT name FROM sqlite_master")
files = res.fetchall()
return files
def retrieve_text(self, name):
res = self.cur.execute(f"SELECT text FROM sqlite_master WHERE name='{name}'")
res.fetchone()
def read_docx():
pass
def write_docx(first_name, second_name, text):
doc = docx.DocxTemplate("my_word_template.docx")
context = { 'first_name' : f"{first_name}", 'second_name' : f"{second_name}", 'text' : f"{text}" }
doc.render(context)
doc.save("generated_doc.docx")
class UI:
def __init__(self) -> None:
self.r = tk.Tk()
self.r.title('Text to docx')
self.label = tk.Label(self.r, text="Edit this text to change the output file")
self.label.pack()
self.text_input = scrolledtext.ScrolledText(self.r)
self.text_input.pack()
self.button = tk.Button(self.r, text='Get text', width=25, command=self.get_text)
self.button.pack()
self.button = tk.Button(self.r, text='Stop', width=25, command=self.r.destroy)
self.button.pack()
def get_text(self):
text = self.text_input.get("1.0", tk.END)
print(text)
def change_text(self, new_text):
self.text_input.config(text=new_text)
if __name__ == "__main__":
ui = UI()
db = database()
ui.r.mainloop()