| Conditions | 3 |
| Total Lines | 47 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import tkinter as tk |
||
| 12 | def __init__(self, message, button1, button2, title, text): |
||
| 13 | """ |
||
| 14 | Args: |
||
| 15 | message (instance): 親ウインドウインスタンス |
||
| 16 | button1 (str): ボタンのメッセージ |
||
| 17 | button2 (bool): キャンセルボタンを表示する(True) |
||
| 18 | title (str): タイトル |
||
| 19 | text (bool): 選択状態にする(True) |
||
| 20 | |||
| 21 | """ |
||
| 22 | self.txt = "" |
||
| 23 | self.sub_name_win = tk.Toplevel(message) |
||
| 24 | self.txt_name = ttk.Entry(self.sub_name_win, width=40) |
||
| 25 | self.txt_name.grid( |
||
| 26 | row=0, |
||
| 27 | column=0, |
||
| 28 | columnspan=2, |
||
| 29 | padx=5, |
||
| 30 | pady=5, |
||
| 31 | sticky=tk.W+tk.E, |
||
| 32 | ipady=3 |
||
| 33 | ) |
||
| 34 | button = ttk.Button( |
||
| 35 | self.sub_name_win, |
||
| 36 | text=button1, |
||
| 37 | width=str(button1), |
||
| 38 | padding=(10, 5), |
||
| 39 | command=self.sub_name_ok |
||
| 40 | ) |
||
| 41 | button.grid(row=1, column=0) |
||
| 42 | if button2: |
||
| 43 | button = ttk.Button( |
||
| 44 | self.sub_name_win, |
||
| 45 | text=u'キャンセル', |
||
| 46 | width=str(u'キャンセル'), |
||
| 47 | padding=(10, 5), |
||
| 48 | command=self.sub_name_win.destroy |
||
| 49 | ) |
||
| 50 | |||
| 51 | button.grid(row=1, column=1) |
||
| 52 | self.txt_name.focus() |
||
| 53 | if text is not False: |
||
| 54 | self.txt_name.insert(tk.END, text) |
||
| 55 | self.txt_name.select_range(0, 'end') |
||
| 56 | |||
| 57 | self.sub_name_win.title(title) |
||
| 58 | self.txt_name.focus() |
||
| 59 | |||
| 76 |