Completed
Pull Request — master (#52)
by Yoshihiro
04:22
created

mydialog.Mydialog.sub_name_ok()   A

Complexity

Conditions 1

Size

Total Lines 16
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 2
dl 0
loc 16
rs 10
c 0
b 0
f 0
1
import tkinter as tk
2
import tkinter.ttk as ttk
3
4
5
class Mydialog():
6
    """ダイアログ作成クラス
7
8
    ・自作ダイアログを呼び出し表示する。
9
10
    """
11
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
60
    def sub_name_ok(self, event=None):
61
        """ダイアログボタンクリック時の処理
62
63
        ・自作ダイアログのボタンをクリックしたときにインプットボックスに
64
        入力されている値を取得する。
65
66
        Args:
67
            event (instance): tkinter.Event のインスタンス
68
69
        Returns:
70
            str: インプットボックスの値
71
72
        """
73
        self.txt = self.txt_name.get()
74
        self.sub_name_win.destroy()
75
        return self.txt
76