Passed
Push — master ( c14483...ae10f4 )
by Yoshihiro
56s queued 30s
created

MD.MyDialogClass.__init__()   A

Complexity

Conditions 3

Size

Total Lines 38
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 33
nop 6
dl 0
loc 38
rs 9.0879
c 0
b 0
f 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