2015-01-22 4 views
-4

내 UI의 버튼을 눌렀을 때 스크립트가 실행되도록하려고합니다. 어떻게 작동 시킬지 모르겠습니다. 어떤 아이디어?Tkinter를 사용하여 파이썬 스크립트를 어떻게 실행합니까?

예 :

from tkinter import * 

root = Tk() 

def OpenPro1(): 

    print("Hej") 

button_1 = Button(root, text = "Hejdå", command = OpenPro1) 

button_1.pack() 


root.mainloop() 

대신의 나는 그것이 프로그램을 실행하려는 텍스트를 인쇄!

+2

... 적절한 함수를 호출? 'OpenPro1'이'print ("Hej")'가 아닌 다른 것을하기를 원할 경우, 그냥 ** 변경하십시오 **! – jonrsharpe

+0

여기에 무슨 문제가 있습니까? – ForceBru

+0

결과를 보려면 터미널 창을보십시오 – ForceBru

답변

1

당신의 텍스트는 유니 코드 문자를 고려해야합니다 :

from Tkinter import * 

root = Tk() 

def OpenPro1(): 
    print("Hej") 

button_1 = Button(root, text = u'Hejd\xe5', command = OpenPro1) 
button_1.pack() 

root.mainloop() 
+0

어떻게 작동합니까, Aroronon? –

1
from tkinter import * 

root = Tk() 

def OpenPro1(): 

    print("Hej") 

    execfile('anyfile.py') #write any file with .py extension.This method is similar to rightclick and open 

button_1 = Button(root, text = "Hejdå", command = OpenPro1) 

button_1.pack() 


root.mainloop()