import tkinter win = tkinter.Tk() # 创建窗口 win.mainloop() # 运行窗口
import tkinter win = tkinter.Tk() win.title('window') # 设置标题 win.geometry('300x200') # 设置窗口大小 win.mainloop()
import tkinter win = tkinter.Tk() win.title('window') win.geometry('300x200') lbl = tkinter.Label(win, text='hello', font=(None, 80)) # 创建组件 lbl.pack() # 将组件放置在窗口上 win.mainloop()
import tkinter win = tkinter.Tk() win.title('window') win.geometry('300x200') btn = tkinter.Button(win, text='hello', font=(None, 24), height=1) # 设置高度 btn.pack() ent = tkinter.Entry(win, font=(None, 24), width=10) # 设置宽度 ent.pack() win.mainloop()
import tkinter def hello(): print("hello") win = tkinter.Tk() win.title('window') win.geometry('300x200') btn = tkinter.Button(win, text='hello', font=(None, 24), command=hello) btn.pack() win.mainloop()
import tkinter def hello(name): print("hello:", name) win = tkinter.Tk() win.title('window') win.geometry('300x200') btn = tkinter.Button(win, text='hello', font=(None, 24), command=lambda: hello('tkinter')) btn.pack() win.mainloop()
import tkinter def hello(name): print("hello:", name) win = tkinter.Tk() win.title('window') win.geometry('300x200') ent = tkinter.Entry(win, font=(None, 24)) ent.pack() btn = tkinter.Button(win, text='hello', font=(None, 24), command=lambda: hello(ent.get())) btn.pack() win.mainloop()