Tkinter | ttk.Entryウィジェットを使用して入力されたテキストにスタイルを追加する

ログインウィジェットは、ユーザーからエントリを取得するために使用されます。次のように作成できます。

 entry = ttk.Entry(master、option = value、...)

コード#1:作成ウィジェットエントリとユーザー入力の取得(文字列データのみの取得)。

#tkinter imports

from tkinter import *

from tkinter import ttk

from tkinter.messagebox import askyesno


#ルートの作成

ルート = Tk()


#ジオメトリを指定する < p> root.geometry( ’200x100’


#これはユーザーからの入力を取得するために使用されます
#そしてそれをエントリーウィジェットに表示します。
#キーボードから受信するデータはすべて
#文字列として扱われます。

input_text = StringVar()

entry1 = ttk.Entry(root、textvariable = input_text、justify = CENTER)


#フォーカスに使用されるfocus_force
#アプリケーションが起動するとすぐに
entry1.focus_force()

entry1.pack(side = TOP、ipadx = 30 、ipady = 6

保存 = ttk.Button(root、text = ’保存’ 、コマンド = lambda :askyesno(

’確認’ ’保存しますか? ’ ))

save.pack(side = TOP、pady = 10


root.mainloop()

出力:

上記の出力で、コードを入力すると、ボタンを押すと、テキストを保存するかどうかを尋ねる確認メッセージが表示されます(テキストは保存されません。使用のみボタンの機能を表示します)。

コード#2:入力ウィジェットに入力されたテキストにスタイルを追加します。

< td class = "code">

#tkinter import

from tkinter import *

from tkinter import ttk

from tkinter.messagebox import askyesno


#ルートを作成

root = Tk()

root.geometry( ’200x100’

input_text = StringVar()


#このクラスはスタイルを追加するために使用されます
#利用可能なウィジェットへ

スタイル = ttk.Style()

style.configure( ’TEntry’ 、フォアグラウンド = ’green’

entry1 = ttk。エントリ(root、textvariable = input_text、justify = CENTER、

font = ’courier’ 15 ’bold’ ))

entry1.focus_force()

entry1.pack(side = TOP、ipadx = 30 、ipady = 10

保存 = ttk。ボタン(ルート、テキスト = ’保存’ 、コマンド = lambda :askyesno(

’確認’ ’保存しますか?’ ))

save.pack(side = TOP、pady = 10


root.mainloop()

出力:

上記の出力では、フォントの色が変更され、フォントファミリが変更され、テキストがlaであることに気付く場合があります。通常よりも大きく、テキストは太字で示されています。これは、入力するテキストにスタイルを追加しているためです。

この記事が問題の解決に役立つことを願っています。 Tkinter | ttk.Entryウィジェットを使用して入力されたテキストにスタイルを追加する とは別に、他の Python functions 関連のトピックを確認してください。

Python で上達したいですか?  最高の Python オンライン コース 2023 のレビューをご覧ください。 データ サイエンスに興味がある場合は、R でプログラミングを学ぶ方法も確認してください。

ちなみに、この資料は他の言語でも利用できます:



Davies Robinson

Warsaw | 2023-03-30

私はコーディングの面接の準備をしていました、これを明確にしてくれてありがとう - PythonのTkinter | ttk.Entryウィジェットを使用して入力されたテキストにスタイルを追加するは最も単純なものではありません. フィードバックで明日戻ってきます

Marie Emmerson

Boston | 2023-03-30

もしかしたら、別の答えがあるのかも?何 Tkinter | ttk.Entryウィジェットを使用して入力されたテキストにスタイルを追加する はどういう意味ですか?. フィードバックで明日戻ってきます

Frank Emmerson

Rome | 2023-03-30

説明ありがとうございました 何時間かTkinter | ttk.Entryウィジェットを使用して入力されたテキストにスタイルを追加するで詰まってました、やっと出来ました🤗。. それが最良の方法であるかどうかはわかりません

Shop

Gifts for programmers

Learn programming in R: courses

$FREE
Gifts for programmers

Best Python online courses for 2022

$FREE
Gifts for programmers

Best laptop for Fortnite

$399+
Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best computer for crypto mining

$499+
Gifts for programmers

Best laptop for Sims 4

$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 answers


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically