在Text 组件中插入对象,可以使用 window_create() 和 image_create() 方法:import tkinter as tk root = tk.Tk() text = tk.Text(root, width=20, height=5) text.pack() text.insert("insert", "I love Python!") def show(): print("哎呀,我被点了一下~") b1 = tk.Button(text, text="...
要使用多行文本框显示图像,使用 image_create() 方法。 import tkinter as tk root = tk.Tk() root.geometry('600x400+200+200') root.title('Text 多文本框演示') text = tk.Text(root, height=10, font=("Arial", 20)) text.pack(padx=10, pady=10) photo=tk.PhotoImage(file='logo.png') ...
1fromtkinterimport*23root =Tk()4text = Text(root,width=20,height=15)5text.pack()6defshow():7text.insert(INSERT,"i love python")8print(text.get("1.2", 1.6))9b1 = Button(text,text="点我",command=show)10text.window_create(INSERT,window=b1) 执行结果: 2. “line.end” 行号加上字...
w1.insert(END,'[kkk]') def returnText(self): print("所有的文本:"+self.w1.get(1.0,END)) def addImage(self): self.photo = PhotoImage(file = "imgs/1.gif") self.w1.image_create(END,image=self.photo) def addWidget(self): b1 = Button(self.w1 ,text = "ffff") self.w1.window_...
text.image_create(END, image=photo)#用这个方法创建一个图片对象,并插入到“END”的位置 text.pack() root.mainloop() 1. 2. 3. 4. 5. 6. 7. 8. 运行结果: 与图片操作有关的一些方法: (1)image_cget(index, option=),返回option后面给定的参数的值,option可以等于file,name,ganma等参数。
要用tkinter在画布上显示图片,首先要装入图片,然后使用canvas对象上的create_image函数。 这是我存在E盘上的一张图片: 我们可以这样来显示one.gif图片: 代码语言:javascript 代码运行次数:0 运行 AI代码解释 >>>from tkinterimport*>>>tk=Tk()>>>canvas=Canvas(tk,width=400,height=400)>>>canvas.pack()>>...
b1 = Button(text,text='唱吧',command=show).place(x=0,y=0) def show1(): text.image_create(END,image=photo) b2 = Button(text,text='看吧',command=show1).place(x=0,y=35) text.window_create(INSERT,window=b1) text.window_create(END,window=b2) ...
text.tag_config("tag_1", foreground="red") text.insert("insert", "林四儿") text.insert("end", "最帅", "tag_1") root.mainloop() 图5.2 tag_config的用法 在Text 组件中插入对象,可以使用 window_create() 和 image_create() 方法。前者可以插入其他控件,后者则可以插入图片,例如在文本框中插...
import tkinter as tkroot = tk.Tk()root.geometry('600x400+200+200')root.title('Text 多文本框演示')text = tk.Text(root, height=10, font=("Arial", 20))text.pack(padx=10, pady=10)photo=tk.PhotoImage(file='logo.png')text.image_create(tk.INSERT, image=photo)text.insert(tk.INSERT,...
用法:在Canvas组件上绘制对象,可以用create_xx()的方法,xx表示对象类型,例如线段line,矩形rectangle,文本text ,扇形arc,图片image,圆oval。# 创建一个矩形,指定画布的颜色为白色from tkinter import *root = Tk()cv = Canvas(root, bg='white')cv.create_rectangle(10, 10, 200, 200)cv.pack()root...