| Total Complexity | 4 |
| Total Lines | 73 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import tkinter as tk |
||
| 2 | import tkinter.ttk as ttk |
||
| 3 | |||
| 4 | |||
| 5 | class MyDialogClass(): |
||
| 6 | """ダイアログ作成クラス |
||
| 7 | |||
| 8 | ・自作ダイアログを呼び出し表示する。 |
||
| 9 | |||
| 10 | Args: |
||
| 11 | message (instance): 親ウインドウインスタンス |
||
| 12 | caption (str): ボタンのメッセージ |
||
| 13 | cancel (bool): キャンセルボタンを表示する(True) |
||
| 14 | title (str): タイトル |
||
| 15 | text (bool): 選択状態にする(True) |
||
| 16 | |||
| 17 | """ |
||
| 18 | def __init__(self, message, caption, cancel, title, text): |
||
| 19 | self.txt = "" |
||
| 20 | self.sub_name_win = tk.Toplevel(message) |
||
| 21 | self.txt_name = ttk.Entry(self.sub_name_win, width=40) |
||
| 22 | self.txt_name.grid( |
||
| 23 | row=0, |
||
| 24 | column=0, |
||
| 25 | columnspan=2, |
||
| 26 | padx=5, |
||
| 27 | pady=5, |
||
| 28 | sticky=tk.W+tk.E, |
||
| 29 | ipady=3 |
||
| 30 | ) |
||
| 31 | button = ttk.Button( |
||
| 32 | self.sub_name_win, |
||
| 33 | text=caption, |
||
| 34 | width=str(caption), |
||
| 35 | padding=(10, 5), |
||
| 36 | command=self.sub_name_ok |
||
| 37 | ) |
||
| 38 | button.grid(row=1, column=0) |
||
| 39 | if cancel: |
||
| 40 | button2 = ttk.Button( |
||
| 41 | self.sub_name_win, |
||
| 42 | text=u'キャンセル', |
||
| 43 | width=str(u'キャンセル'), |
||
| 44 | padding=(10, 5), |
||
| 45 | command=self.sub_name_win.destroy |
||
| 46 | ) |
||
| 47 | |||
| 48 | button2.grid(row=1, column=1) |
||
| 49 | self.txt_name.focus() |
||
| 50 | if text is not False: |
||
| 51 | self.txt_name.insert(tk.END, text) |
||
| 52 | self.txt_name.select_range(0, 'end') |
||
| 53 | |||
| 54 | self.sub_name_win.title(title) |
||
| 55 | self.txt_name.focus() |
||
| 56 | |||
| 57 | def sub_name_ok(self, event=None): |
||
| 58 | """ダイアログボタンクリック時の処理 |
||
| 59 | |||
| 60 | ・自作ダイアログのボタンをクリックしたときにインプットボックスに |
||
| 61 | 入力されている値を取得する。 |
||
| 62 | |||
| 63 | Args: |
||
| 64 | event (instance): tkinter.Event のインスタンス |
||
| 65 | |||
| 66 | Returns: |
||
| 67 | str: インプットボックスの値 |
||
| 68 | |||
| 69 | """ |
||
| 70 | self.txt = self.txt_name.get() |
||
| 71 | self.sub_name_win.destroy() |
||
| 72 | return self.txt |
||
| 73 |