import tkinter as tk
#import sys
import os
root = tk.Tk()
def open_calc():
os.system("calc")
def open_chrome():
os.system("start chrome")
def open_code():
os.system("Code")
root.title("Thonny window")
lbl1 = tk.Label(root,text='I am Thonny')
#lbl1.pack(side="top")
lbl1.pack(side="left")
btn=tk.Button(root,text='Start 计算器',command=open_calc)
btn.pack(side='left')
btn=tk.Button(root,text='打开浏览器',command=open_chrome)
btn.pack(side='left')
btn=tk.Button(root,text='Start vs Code',command=open_code)
#btn.pack(side='bottom')
btn.pack(side='left')
#root.mainloop()
另一段程序,应用了act函数
from tkinter import *
#import sys
import os
tk = Tk()
def act():
print(sys.platform)
print(os.system("dir"))
print(os.system("winver"))
print(os.system("notepad"))
os.system("code")
Label(tk,text="The first Program").pack(side="left")
Entry(tk).pack(side="left")
Button(tk,text="确定",command=act).pack(side="left")
tk.mainloop()