2017-01-14 67 views
0

私は一度クリックすると、スクリプト全体を再起動することができます再起動ボタンを作成することができますか?私が思ったのは、あなたがウインドウを破壊した後、それを破壊するというものでしたが、明らかに破棄されない機能はありませんでした。プログラムを再起動するtkinter

+0

は、[メインGUIウィンドウをリセット]のhttp://stackoverflow.com/q/731887/1072229 –

+2

可能な重複のだまされやすい人のように思える(HTTP :/stackoverflow.com/questions/731887/resetting-the-main-gui-window) –

答えて

2

私はこのウェブサイトの一般的なpythonプログラムのための方法を見つけました:https://www.daniweb.com/programming/software-development/code/260268/restart-your-python-program。私はそれをテストするための基本的なTkinterのGUIをして例を書いた:

import sys 
import os 
from tkinter import Tk, Label, Button 

def restart_program(): 
    """Restarts the current program. 
    Note: this function does not return. Any cleanup action (like 
    saving data) must be done before calling this function.""" 
    python = sys.executable 
    os.execl(python, python, * sys.argv) 

root = Tk() 

Label(root, text="Hello World!").pack() 
Button(root, text="Restart", command=restart_program).pack() 

root.mainloop() 
関連する問題