LoginSignup
1
2

More than 1 year has passed since last update.

tkinterのテキストボックスを入力選択状態にする方法:ショートカットキーでテキストボックスの選択する方法

Last updated at Posted at 2021-05-24

概要

tkinterでアプリのようなものを作っていて、ショートカットキーで入力ボックスを選択する方法がなかなか見つからなかったため、記事にします。

結論

txtBox_name.focus_set()

でできます。

Shift + G :2個めのテキストボックスを選択
Shift + F :1個目のテキストボックスの内容を2個目に移動
ボタン   :1個目のテキストボックスの内容を2個目に移動

image.png

import tkinter as tk

def next_box(event):
    editbox2.delete(0,tk.END)
    editbox2.insert(tk.END,editbox.get()) 

    editbox.delete(0,tk.END)

def select_box(event):
    editbox2.focus_set()

root = tk.Tk()
root.title(u"テスト画面")
root.geometry("400x200")

editbox = tk.Entry()
editbox.pack()

editbox2 = tk.Entry()
editbox2.pack()

button = tk.Button(text = '次ページ',width = 30)
button.pack()
button.bind('<Button-1>',next_box)


root.bind('<Shift-Key-F>',next_box)
root.bind('<Shift-Key-G>',select_box)
#root.bind('<Enter>',next_page)  #挙動がおかしい気がする

root.mainloop()

root.mainloop()
1
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2