Study Notes (40): Python actual programming - text

Learning immediately: https://edu.csdn.net/course/play/19711/343102?utm_source=blogtoedu

Text - computer interaction, where entered text (tkinter.Text ( "Text to be displayed", set the property) component class)

 

Knowledge points:

Text Input

The default text display: insert

The image is displayed by default settings: text.image_create (location to be displayed, picture objects displayed)

 

import tkinter,os

image_path = r'C:\Users\jinlin\Desktop\python_further_study\resources'  + os.sep + 'linlianqin.gif'#只支持gif格式的图片

class Mainwindow():#创建窗口类
    def __init__(self):
        root = tkinter.Tk()#创建主体窗口

        #-------------以下是普通文本的设置----------------
        text = tkinter.Text(root,font = ("微软雅黑","18"))#创建文本,指定文本框显示的窗口,以及输入文本的大小
        text.insert(tkinter.CURRENT,'linlianqin')#设置文本框的默认显示文字,在当前打开
        text.pack()#文本显示


        #------------以下是文本插入图片的设置---------------
        photo = tkinter.PhotoImage(file = image_path)#对需要操作的图片进行创建
        text.image_create(tkinter.END,image = photo)
        text.pack()


        root.mainloop()#显示窗口

if __name__ == '__main__':
    Mainwindow()#将窗体类实例化

 

Published 61 original articles · won praise 11 · views 886

Guess you like

Origin blog.csdn.net/qq_45769063/article/details/105182601