Passed
Push — master ( acaf9b...fbbf97 )
by Yoshihiro
44s queued 10s
created

MD   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 41
dl 0
loc 75
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

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