【发布时间】:2020-03-31 23:04:24
【问题描述】:
编辑器工作完美,但有一个很小的问题是,当我选择“粗体”时,字体样式“斜体”会自动取消选中,而当我“下划线”时,粗体和斜体文本会被取消选中,简而言之,一个功能只在每次工作。 我尝试了所有可能的用代码注释的方式
#BOLD BUTTON FUNCTIONALITY
def change_bold():
text_property = tk.font.Font(font = text_editor['font'])
if text_property.actual()['weight'] == 'normal':
text_editor.configure(font= (current_font_family, current_font_size, 'bold'))
if text_property.actual()['weight'] == 'bold':
text_editor.configure(font= (current_font_family, current_font_size, 'normal'))
if text_property.actual()['slant'] == 'italic':
text_editor.configure(font= (current_font_family, current_font_size, 'bold','italic'))
bold_button.configure(command = change_bold)
# ITALIC BUTTON FUNCTIONALITY
def change_italic():
text_property = tk.font.Font(font = text_editor['font'])
if text_property.actual()['slant'] == 'roman':
text_editor.configure(font= (current_font_family, current_font_size, 'italic'))
if text_property.actual()['slant'] == 'italic':
text_editor.configure(font= (current_font_family, current_font_size, 'normal'))
if text_property.actual()['weight'] == 'bold':
text_editor.configure(font= (current_font_family, current_font_size, 'bold','italic'))
italic_button.configure(command = change_italic)
# UNDERLINE BUTTON FUNCTIONALITY
def change_underline():
text_property = tk.font.Font(font = text_editor['font'])
if text_property.actual()['underline'] == 0:
text_editor.configure(font= (current_font_family, current_font_size, 'underline'))
if text_property.actual()['underline'] == 1:
text_editor.configure(font= (current_font_family, current_font_size, 'normal'))
# if text_property.actual()['weight'] == 'normal' and text_property.actual()['slant'] == 'roman':
# text_editor.configure(font= (current_font_family, current_font_size, 'normal','roman',1))
# if text_property.actual()['weight'] == 'bold' and text_property.actual()['slant'] == 'roman':
# text_editor.configure(font= (current_font_family, current_font_size, 'bold','roman',1))
# if text_property.actual()['weight'] == 'bold' and text_property.actual()['slant'] == 'italic':
# text_editor.configure(font= (current_font_family, current_font_size, 'bold','italic',1))
# if text_property.actual()['weight'] == 'normal' and text_property.actual()['slant'] == 'italic':
# text_editor.configure(font= (current_font_family, current_font_size, 'normal','italic',1))
underline_button.configure(command = change_underline)
这张图片是我的文本编辑器的外观
下划线
粗体
斜体
【问题讨论】:
-
欢迎来到 StackOverflow!你的问题是什么?此外,您可能会发现 creating minimal, reproducible examples 上的帮助中心页面有助于在此站点上提出问题。