tkinter

 

import tkinter as tk
from tkinter import Label, END, Entry, Text, Button
from tkinter import *
class Mytkinter(object):
    def __init__(self):
        self.on=False
        self.wd=tk.Tk()
        self.wd.title('my tkinter ')
        self.wd.geometry('300x250+600+300')

        self.lable=Label(self.wd,bd=3,text='我是一个lable',bg='blue',font=('Arial',12),width=20,height=2,fg='#DCDCDC')
        self.lable.pack()
        self.Button=Button(self.wd,text='点我!',height=1,command=self.hit_me,bg='white',bd=2)
        self.Button.pack()
        self.entry=Entry(self.wd,width=20,font=('Arial',13),fg='yellow',show='*')
        self.entry.pack()
        self.text=Text(self.wd,width=280,font=('Arial',12),fg='blue',height=2)
        self.text.pack()
        self.var=tk.StringVar()
        self.var.set((1,2,3,4))
        self.select=Listbox(self.wd,listvariable=self.var,height=5)
        self.select.pack()
        self.button2=Button(self.wd,text='选择按钮',height=1,command=self.get_select)
        self.button2.pack()

    def hit_me(self):
        if self.on == False:
            
            self.lable['bg']='red'
            self.lable['text']='我是谁'
            self.lable['width']=30
            self.lable['height']=1
            self.entry['textvariable']='12356'
            text=self.entry.get()
            self.text.insert(2.1,text)
            self.select.insert('1')
            self.on =True
        else:
            self.lable['bg']='yellow'
            self.lable['text']='我在哪'
            self.lable['width']=15
            self.lable['height']=3
            text=self.entry.get()
            self.text.insert(END,text)
            self.on=False

    
    def get_select(self):
        var=self.select.get(self.select.curselection())
        self.text.insert(END,var)

    def run(self): 
        self.wd.mainloop()


if __name__ == '__main__':
    m=Mytkinter()
    m.run()

tkinter 基本四大组件 

 

你可能感兴趣的:(Tkinter)