思路来源
自己实现的效果图
自己写的代码
[Python] 纯文本查看 复制代码 from tkinter import *
root = Tk()
root.geometry('500x300+300+200')
root.config(bg='lightblue')
cv = Canvas(root,width=400,height=270,bg='white')
cv.pack()
bitmaps = ["error", "gray75", "gray50", "gray25", "gray12",
"hourglass", "info", "questhead", "question", "warning"]
# for循环遍历bitmaps的长度 每次遍历 都使用create_bitmap()方法来创建位图
# 前面两个参数是位图的位置 后面那个参数是位图名称
for i in range(len(bitmaps)):
cv.create_bitmap((i+1)*30,30,bitmap=bitmaps[i])
text = cv.create_text(30,80,text='tkinter内置位图预览',font=('微软雅黑',18,'bold'),anchor='w',fill='green')
# 用PhotoImage()方法来加载图片
img = PhotoImage(file=r'D:\Pictures\QQ截图20221220115757.png')
image = cv.create_image(30,140,image=img,anchor='w')
text = cv.create_text(30,200,text='图片预览',font=('微软雅黑',16,'bold'),anchor='w',fill='green')
root.mainloop() AI对代码的解释
|