当我按下UI上的按钮时,我正试图让我的脚本运行,不知道如何让它工作。有什么想法吗?
示例:
from tkinter import *
root = Tk()
def OpenPro1():
print("Hej")
button_1 = Button(root, text = "Hejdå", command = OpenPro1)
button_1.pack()
root.mainloop()
而不是打印文本我希望它运行程序!
答案 0 :(得分:1)
您的文字必须考虑到unicode字符:
from Tkinter import *
root = Tk()
def OpenPro1():
print("Hej")
button_1 = Button(root, text = u'Hejd\xe5', command = OpenPro1)
button_1.pack()
root.mainloop()
答案 1 :(得分: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()