12、弹窗 messagebox
import tkinter as tk from tkinter import messagebox root = tk.Tk() root.title("xxx") root.geometry('200x100') def hit_me(): # tk.messagebox.showinfo(title='Hi', message='hahaha') # message 给窗口的信息,图标是python火箭 # tk.messagebox.showwarning(title='Hi', message='程序有错, 是否修改下执行') # 提示信息框 ,图标是感叹号 # tk.messagebox.showerror(title='Hi', message='程序错了不能再运行了') # tk.messagebox.askquestion(title='Hi', message='yes or no') # 问用户信息,有返回值,返回值是yes和no # if return == 'yes': # print('xxxx') # tk.messagebox.askyesno(title='Hi', message='yes or no') # 返回的是 False 和 True print(tk.messagebox.askretrycancel(title='Hi', message='yes or no')) # 返回的是 重试True 和取消False print(tk.messagebox.askokcancel(title='Hi', message='yes or no')) # 第一次返回的是 重试True 和取消False # 第二次返回的是 确定True 和取消False tk.Button(root, text='hit me', command=hit_me).pack() root.mainloop()
13、放置位置 pack grid place
import tkinter as tk root = tk.Tk() root.title("xxx") root.geometry('200x100') # pack方法 # tk.Label(root, text=1).pack(side='top') # 上 # tk.Label(root, text=1).pack(side='bottom') # 下 # tk.Label(root, text=1).pack(side='left') # 左 # tk.Label(root, text=1).pack(side='right') # 右 # grid方法12格子方法, 4行, 3列 # for i in range(4): # for j in range(3): # # row 行 column 列 padx 长 pady 高 # tk.Label(root, text=1).grid(row=i, column=j, padx=10, pady=10) # palce 精准放置 tk.Label(root, text=1).place(x=10, y=100, anchor='nw') # anchor 放在哪个角部 root.mainloop()