#!/usr/bin/python3
# -*- coding: UTF-8 -*-
from tkinter import *
root = Tk()
root.title("Tkinter GUI - 按钮") # 设置标题
root.geometry("200x300-100+100") # 设置窗口大小和起始位置
def showMsg():
# # 单独设置样式
# label1["text"] = "I Love Python"
# label1["bg"] = "lightyellow"
# label1["fg"] = "blue"
# # 批量设置样式
label1.config(text="I Love Python", bg="lightyellow", fg="blue")
# # 001. 点击按钮显示文字
# label1 = Label(root)
# button1 = Button(root, text="打印消息", command=showMsg)
# label1.pack()
# button1.pack()
# # 002. 点击按钮1显示文字,按钮2关闭窗口
# label1 = Label(root)
# button1 = Button(root, text="打印消息", width=15, command=showMsg)
# button2 = Button(root, text="关闭窗口", width=15, command=root.destroy)
# label1.pack()
# button1.pack(side="left")
# button2.pack(side="left")
# # 003. 用图片代替文字
# label1 = Label(root)
# # 图片路径建议使用绝对路径
# sunGif = PhotoImage(file="test.gif")
# button1 = Button(root, image=sunGif,command=showMsg)
# label1.pack()
# button1.pack(side="left")
# # 004. 图文共存
# label1 = Label(root)
# sunGif = PhotoImage(file="test.gif")
# # 图片在上
# # button1 = Button(root, text="Click Me", image=sunGif,
# # compound="top", command=showMsg)
# # 图片文字重叠
# button1 = Button(root, text="Click Me", image=sunGif,
# compound="center", command=showMsg)
# label1.pack()
# button1.pack(side="left")
# 005. 用图片代替文字
label1 = Label(root)
button1 = Button(root, text="注意鼠标光标", cursor="star", command=showMsg)
label1.pack()
button1.pack(side="left")
root.mainloop()