Playlist: Playlist: Python Tutorial Lessons to do Double Double Text Editor with Microsoft Text to Speech in English and Deutsch There is Python Code in the Description • Python Tutorial Lessons to do Doubl...
The following lines of text show the code in Python Tkinter as the best solution for encoding UTF-8. Such a code is necessary to open and save special characters.
Lessons 7 Code
from tkinter import *
from tkinter import filedialog
import os
import os.path
import lib_programname
python -m pip install lib_programname
................................................................................................................
app_executed_script_dir_path = StringVar()
app_executed_script_dir_path = executed_script_dir_path()
.........................................................................................................
def set_text(text, obj):
obj.delete(0,END)
obj.insert(0,text)
e1_absolute_default_storage_relative_filename = StringVar()
e1_absolute_default_storage_relative_filename = app_executed_script_dir_path + "\\e1_default_relative_filename.txt"
e1_absolute_storage_relative_filename = StringVar()
e1_absolute_storage_relative_filename = app_executed_script_dir_path + "\\e1_relative_filename.txt"
.............................................
e1 = Entry(w, justify='center')
e1.pack()
e1.place(x=43, y=452 + 22, width=444, height=21)
e1.focus_set()
e1.insert(0, "")
e2 = Entry(w, justify='center')
e2.pack()
e2.place(x=43, y=475 + 24, width=444, height=22)
e2.insert(0, "")
..........................................................................................
def db_open():
s1 = "Script dir (db_location): "
s2 = app_executed_script_dir_path
l is the identifier
for the memory space
in which
there is an instance
of code of object of type Label
l = Label(w, text=_s_)
l.pack(pady=5)
l.place(x=9, y=576)
l.config(text=s1+s2)
selected_filename = filedialog.askopenfilename(
filetypes=[("Text files","*.txt")],
initialdir=app_executed_script_dir_path,
title="e1 Open Keywords Fille")
if(selected_filename != None):
if (selected_filename.find('.txt') !=-1):
f = open(selected_filename, encoding ='utf-8')
l1.config(text=selected_filename)
set_text(selected_filename, e2)
s=f.read()
selected_basename_name_of_file = os.path.basename(selected_filename)
selected_dirname = os.path.dirname(selected_filename)
set_text(selected_basename_name_of_file, e1)
set_text(s, e2)
b_db_save_as["state"] = "active"
b_db_open = Button(w, text =" db Open ", command = db_open)
b_db_open.pack(padx=10, pady=2)
b_db_open.place(x=482-12, y=573-26)
def db_save_new_relative_filename(filename):
show filename
l1.config(text=filename)
l2.config(text="")
get the content of the Entry Box
new_content = e2.get()
encoding the string new_content
with open(filename, 'w', encoding='utf-8') as f:
f.write(new_content)
#f = open(filename, "w")
#f.write(new_content)
f.close()
b_db_save_as["state"] = "disabled"
def db_asksaveasfile():
seleted_full_path = app_executed_script_dir_path + "\\" + e1.get()
Do not delete
basename_name_of_file = os.path.basename(seleted_full_path)
dirname = os.path.dirname(seleted_full_path)
initial_dir = app_executed_script_dir_path
l1.config(text=basename_name_of_file)
chosen_filename = filedialog.asksaveasfile(mode='w'
, filetypes=[("Text files","*.txt")]
, initialdir=initial_dir
, defaultextension=".txt"
, title="Save As Content from T1 Text Widget")
if(chosen_filename != None):
if (chosen_filename.name.find('.txt') !=-1):
if (check_box_var.get() == 0):
l1.config(text=chosen_filename.name)
db_save_new_relative_filename(chosen_filename.name)
b_db_save_as = Button(w, text ="db Save As", command = db_asksaveasfile)
b_db_save_as.pack(padx=10, pady=2)
b_db_save_as.place(x=471, y=573-49)
b_db_save_as["state"] = "disabled"
def b_activate():
b_db_save_as["state"] = "disabled"
be1_askopenfile["state"] = "active"
be1_asksaveasfile["state"] = "active"
be2_askopenfile["state"] = "active"
be2_asksaveasfile["state"] = "active"
b_activate = Button(w, text =" Activate ", command = b_activate)
b_activate.pack(padx=10, pady=2)
b_activate.place(x=470, y=573)
b_db_save_as["state"] = "disabled"
Смотрите видео L7 Python Tkinter The Best Solution to Open and Save with encoding UTF-8 Python Code in Description онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Tonio FERENER-VARI 17 Декабрь 2022, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 11 раз и оно понравилось lik людям.