Answer the question
In order to leave comments, you need to log in
What should I change in the code so that the created document displays the date selected through the calendar?
Good afternoon, I'm wildly sorry, but I just need to get an explanation, because the second day I'm racking my brains.
Task: to make a program for autofilling one standard document. The program in its current form is generally still far from the ideal I need, but it seems like I have already selected all the combinations of code I need and even planned to finally “comb” it and make the design through Cuti Designer, but there was one snag.
Question: document date. I don’t want to fill it out through the input function, I want the calendar to fly out conveniently and beautifully, you can select a date and it would automatically go into the document. What am I doing wrong, what should I put paragraph.text = paragraph.text.replace("date", ********) instead of asterisks? I can’t assign a variable to a date, or in principle you can’t do it through tkcalendar (but I really want to, I was already so close to completion ((()?
P.S. Do not judge strictly the code as a whole, I am self-taught and in programming week, this is my second program that I'm trying to write for work, in order to learn how to write code and understand the logic of actions
PS 2. In my opinion, tkcalendar does not fit here at all, I'm more and more inclined towards this, what other options are there
? samplehttps://drive.google.com/file/d/1QHLtZfcsVZ8vjkXdk...
from docxtpl import DocxTemplate
from datetime import date
import datetime
from docx.shared import Inches
doc = DocxTemplate("шаблон.docx")
# Номер приказа
number = input ( "Номер предыдущего приказа: " )
n = int (number) + 1
# Данные ответственного
last_names = input ( 'Фамилия ответственного в род. падеже: ' )
first_names = input ( 'Имя ответственного в род. падеже: ' )
add_names = input ( 'Отчество ответственного в род. падеже: ' )
# Сокращение ИО
full_names = str (str (last_names) + ' ' + str (first_names) + ' ' + str (add_names))
short_names = str (str (last_names) + ' ' + str (first_names [0]) + '. ' + str (add_names [0]) + '.')
# Адрес магазина
address = input ( "Адрес магазина: " )
try:
import tkinter as tk
from tkinter import ttk
except ImportError:
import Tkinter as tk
import ttk
from tkcalendar import Calendar
def example1():
def print_sel():
a = str (cal.selection_get())
print (a)
def quit1():
top.destroy()
top = tk.Toplevel(root)
cal = Calendar(top,
font="Arial 14", selectmode='day',
cursor="hand1", year=2021, month=1, day=1)
cal.pack(fill="both", expand=True)
ttk.Button(top, text="ok", command=print_sel).pack()
root = tk.Tk()
s = ttk.Style(root)
s.theme_use('clam')
ttk.Button(root, text='Календарь', command=example1).pack(padx=10, pady=10)
root.mainloop()
for paragraph in doc.paragraphs:
paragraph.text = paragraph.text.replace("name", str (full_names))
paragraph.text = paragraph.text.replace("address", str (address))
paragraph.text = paragraph.text.replace("number", str (n))
paragraph.text = paragraph.text.replace("short", str (short_names))
paragraph.text = paragraph.text.replace("date", ********)
doc.save("test1.docx")<code>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question