0

説明のために簡単なアプリを作成しようとしていました。アイデアは次のとおりです。選択したコース (ラジオ ボタン) にのみ関連付けられたスクリプト ファイルを実行するアプリケーションを作成します。そこで、件名を一覧表示する (クリックする) ラジオ ボタンを作成します。被験者が選択されたら、ユーザーはEnterボタンを押す必要があります。.pyこれにより、選択したサブジェクト (execute_script関数)のすべてのファイルが実行されます。

ただし、コードを実行すると、「なし」と書かれたメッセージボックスが 4 つ表示されます。enter[OK] をクリックすると、ボタンだけの正方形のウィンドウが表示されます。この問題を解決するにはどうすればよいですか?

def check(file_name, relStatus):   
    radioValue = relStatus.get()
    tkMessageBox.showinfo('You checked', radioValue)
    been_clicked.append(file_name)   
    return

def execute_script():
    for name in been_cliked:
        subprocess.Popen(['python', 'C:\Users\Max\Subjects\{}'.format(name)])

    yield


def main():

    #Create application
    app = Tk()
    app.title('Coursework')
    app.geometry('450x300+200+200')

    #Header
    labelText = StringVar()
    labelText.set('Select subjects')

    #Dictionary with names
    product_names = {}
    names = []
    file_name = []
    names = ['Math', 'Science', 'English', 'French']
    file_name = ['calc.py', 'physics.py', 'grammar.py', 'livre.py']
    product_names = OrderedDict(zip(names, file_name))

    #Create radio buttons
    global been_clicked
    been_clicked = []
    relStatus = StringVar()
    relStatus.set(None)
    for name,file_name in product_names.iteritems():
        radio1 = Radiobutton(app, text=name, value=name, \
                         variable=relStatus, command=check(file_name, relStatus))

    button = Button(app, text='Click Here', width=20, command=execute_script())
    button.pack(side='bottom', padx=15, pady=15)

    app.mainloop()


if __name__ == '__main__': main()
4

1 に答える 1