1.创建
from tkinter import *
root=Tk()
root.title('Hello tkinter!')
root.mainloop()
图片.png
2.使用内置位图
from tkinter import *
root=Tk()
label=Label(root,bitmap=’hourglass’)
label.pack()
root.mainloop()
图片.png
还有这些选项 error,hourglass,info,questhead,question,warning,gray12,gray25,gray50,gray75
3.改变颜色和宽高
label=Label(root,fg='red',bg='blue',text='Hello')
label=Label(root,fg='red',bg='blue',text='Hello',width='10',height='3')
4.使用图像与文本
from tkinter import *
root=Tk()
label=Label(root,fg='red',bg='blue',text='Hello',width='100',height='300',bitmap='error')
label.pack()
root.mainloop()
图片.png
from tkinter import *
root=Tk()
label=Label(root,fg='red',bg='blue',text='Hello',width='100',height='300',bitmap='error',compound='right')
label.pack()
root.mainloop()
图片.png
5.文本多行显示
from tkinter import *
root=Tk()
label=Label(root,text='Hello',width='100',height='300',wraplength='1')
label.pack()
root.mainloop()
图片.png
参考资料:
Tkinter编程代码实例-Jcodeer,Zhang
网友评论