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