window_create(index, **options) -- 在 index 参数指定的位置嵌入一个 window 对象 -- 支持两种方式在 Text 组件中嵌入 window 对象:请看下方 create 选项和 window 选项的描述 -- 可选选项 align:设定此图像的垂直对齐,可以是 "top"、"center"、"bottom" 或 "baseline" -
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” 行号加上字...
#在Text控件内插入- -段文字 ,INSERT表示在光标处插入,END表示在末尾处插入 text.insert (INSERT, "在拜仁,你甚至可以踢球") # 跳下一行 text.insert (INSERT, "\n\n") #在Text控件内插入- -个按钮 button = Button(text, text="关闭",command=win.quit) text. window_create (END, window=button) ...
Fayson的github: https://github.com/fayson/cdhproject 提示:代码块部分可以左右滑动查看噢 1.文档编...
text.insert("insert", "林四儿最帅\n") b1 = Button(text, text="点我") b1.pack() text.window_create("insert", window=b1) root.mainloop() 图5.3 文本框中插入按钮 删除刚才创建的按钮: text.delete(b1) Text控件的方法要比Entry丰富得多,也更加灵活,这里我们就只介绍一些十分常用的,如果你有兴...
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) mainloop() 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. ...
要创建多个窗口,可以使用Tkinter模块中的Toplevel类。下面是一个示例代码,演示如何创建多个窗口: import tkinter as tk def create_window(): new_window = tk.Toplevel(root) new_window.title("New Window") root = tk.Tk() root.title("Main Window") button = tk.Button(root, text="Create New ...
button = Button(text, text="关闭",command=win.quit) text. window_create (END, window=button) # 填充水平和垂直方向,这里设置 expand为 True 否则不能垂直方向延展 text .pack (fill=BOTH,expand=True) # 在第一行文字的第0个字符到第6个字符处插入标签,标签名称为"name" ...
Label(root_window,text="C语言中文网,欢迎您",bg="yellow",fg="red",font=('Times', 20, 'bold italic')) text.pack() # 文字标签 button=tk.Button(root_window,text="关闭",command=root_window.quit) button.pack(side="bottom") # 按钮 root_window.mainloop() #开启主循环,让窗口处于显示状态...
#定义一个label l = tk.Label(window, text='Hi! this is TK!', # 标签的文字 b...