Entry ではなく、テキストであれば回転可能です。
python
1 canvas . create_text ( ( 100 , 200 ) , text = "H.900" , angle = 90 )
create_window でウィジェットをキャンバス内に配置できますが、
残念ながら create_windowには angle 指定はできません。
ctypes で無理やり何とかする方法がなくはないですが、プラットフォーム依存で難易度:高
妥協案として、tkinter で実装するなら、StringVar や IntVar で変数を作成し
Entry 入力に応じて、Canvas のテキストに反映する方法です
python
1 import tkinter as tk
2
3 # 変更点:
4 # - Entry を 画面外に配置 (機能は残しつつも非表示)
5 # - テキストクリック時に Entry にフォーカスを移す
6 # - (テキストのフォントサイズ調整)
7
8 # 課題
9 # - Tab で 入力欄を遷移したときに、隠し Entry が含まれる
10 # - 矢印キー操作時、編集中のカーソルが見えない
11
12 def main ( ) :
13 root = tk . Tk ( )
14 heightVar = tk . IntVar ( root , value = 900 )
15 canvas = tk . Canvas ( root , width = 600 , height = 600 )
16 entry = tk . Entry ( root , width = 10 , textvar = heightVar )
17 entry . place ( x = - 10000 , y = - 10000 )
18
19 canvas . pack ( fill = tk . BOTH , expand = True )
20 item = canvas . create_text ( ( 100 , 200 ) , text = "900" , angle = 90 , font = ( "" , 30 ) )
21
22 def _update_text ( * args ) :
23 value = heightVar . get ( )
24 canvas . itemconfigure ( item , text = f"H. { value } " )
25
26 canvas . tag_bind ( item , "<Button-1>" , lambda _ : entry . focus ( ) )
27
28 heightVar . trace ( "w" , _update_text )
29
30 root . mainloop ( )
31
32 if __name__ == '__main__' :
33 main ( )
他環境で入力可能で90度回転だと、
簡単な方法は HTML/CSS の form input 入力欄で可能です。
html
1 <! DOCTYPE html >
2 < html >
3 < head >
4 < title > Roate field demo </ title >
5 < style >
6 input #cell {
7 margin-top : 100 px ;
8 transform : rotate ( -90 deg ) ;
9 }
10 </ style >
11 </ head >
12 < body >
13 < form >
14 < input id = " cell "
15 value = " 900 "
16 />
17 </ form >
18 </ body >
19 </ html >
動作DEMO (Qt/Kivy/Tkinter)
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2024/12/11 05:13
2024/12/11 06:25
2024/12/11 08:47
2024/12/11 16:06 編集
2024/12/12 02:33