日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python加粗_python – 设置为使用标记加粗选定的文本

發布時間:2025/3/15 python 16 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python加粗_python – 设置为使用标记加粗选定的文本 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我一直在努力制作一個簡單的文本編輯器,并一直在試驗標簽.我已經能夠使用標簽創建證明.現在我添加一個粗體選項.

我的問題是我找不到很多使用“sel”標簽的例子,這是當前選擇中使用的標簽.

每當我使用SEL標簽時,只要文本突出顯示,文本就是粗體,當它變為未突出顯示時,它會恢復為舊的瘦字體.

這只是我代碼的一小部分:

def Bold(self, body, Just, Line, selected font):

bold font = tkFont.Font(family=selectedfont, weight="bold")

selected font = boldfont

body.tag_config("sel",font=selectedfont)

body.tag_add("sel", 1.0,END)

按下Bold按鈕時,將調用上一個功能.

現在,我將body.tag_add(“sel”,1.0,END)設置為從1.0到END,因為我不知道如何獲取所選域.

我已經嘗試了<< Selection>>,但經過長時間的實驗,它沒有幫助我.

解決方法:

您只需要在函數內部使用tag_add():

import Tkinter as tk

def make_bold():

aText.tag_add("bt", "sel.first", "sel.last")

lord = tk.Tk()

aText = tk.Text(lord, font=("Georgia", "12"))

aText.grid()

aButton = tk.Button(lord, text="bold", command=make_bold)

aButton.grid()

aText.tag_config("bt", font=("Georgia", "12", "bold"))

lord.mainloop()

我剛剛遇到了一個相當教育的example,而不是Bryan Oakley,

在一個完全不相關的搜索!

以下是更具動態替代方案的快速示例:

import Tkinter as tk

import tkFont

def make_bold():

current_tags = aText.tag_names("sel.first")

if "bt" in current_tags:

aText.tag_remove("bt", "sel.first", "sel.last")

else:

aText.tag_add("bt", "sel.first", "sel.last")

lord = tk.Tk()

aText = tk.Text(lord, font=("Georgia", "12"))

aText.grid()

aButton = tk.Button(lord, text="bold", command=make_bold)

aButton.grid()

bold_font = tkFont.Font(aText, aText.cget("font"))

bold_font.configure(weight="bold")

aText.tag_configure("bt", font=bold_font)

lord.mainloop()

標簽:python,text,tkinter

來源: https://codeday.me/bug/20190613/1233762.html

總結

以上是生活随笔為你收集整理的python加粗_python – 设置为使用标记加粗选定的文本的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。