Study Notes (41): Python actual programming - Button

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

Button - Submit action for the instruction, as will be the message text and the like inputted Submit

 

 button = tkinter.Button(root,text = 'linlianqin',image = photo,compound = 'bottom')

Create a picture button, and there is prompt text text, pictures will be set relative to the text relative positional relationship, namely compound = "bottom"

import tkinter,os#导入创建窗体的相关模块

image_path = image_path = r'C:\Users\jinlin\Desktop\python_further_study\resources'  + os.sep + 'linlianqin.gif'#只支持gif格式的图片
class Mainwindow():#创建窗口类
    def __init__(self):
        root = tkinter.Tk()#创建主体窗口

        #---------------以下是对按钮的设置---------------
        photo = tkinter.PhotoImage(file = image_path)#设置按钮的外观,这里是将图片设置为按钮的外观
        button = tkinter.Button(root,text = 'linlianqin',image = photo,compound = 'bottom')#创建按钮
        button.pack()#显示按钮

        root.mainloop()#显示窗口

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

 

Note: To realize the function button, also you need to specify their event

Published 61 original articles · won praise 11 · views 885

Guess you like

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