1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#http://effbot.org/tkinterbook/label.htm from tkinter import * master = Tk() #w = Label(master, # text="Hello, world!", # fg="red",#设定颜色 # font=("Helvetica", 16),#设定字体大小 # # ) v = StringVar() Label(master, textvariable=v).pack() v.set("New Text!") #w = Label(master, text="Rouge", fg="red") #w = Label(master, text="Helvetica", font=("Helvetica", 16)) photo = PhotoImage(file="icon.gif") w = Label(parent, image=photo) w.photo = photo w.pack() mainloop() |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
from tkinter import * import tkinter as tk from gpiozero import LEDBoard leds = LEDBoard(2, 3, 4, 14, 17,27,22,23,active_high=False) def drawCircle(self,x,y,r,**kwargs): return self.create_oval(x-r,y-r,x+r,y+r,**kwargs) def grab(event): canvas = event.widget item = canvas.find_closest(event.x, event.y) cv.itemconfig(item,fill= cv.itemcget(item,'fill') == 'pink' and 'blue' or 'pink') #leds[0].on() #print (item[0] , c1) t.delete('1.0', END) t.insert(END, '(') for n in range (0,8) : leds[n].on() if cv.itemcget(n+1,'fill') == 'pink' else leds[n].off() t.insert(END, '1' if cv.itemcget(n+1,'fill') == 'pink' else '0') t.insert(END, ',') t.delete('1.16', END) t.insert(END, '),') v.set(t.get(0.0,END))#获取text中文本 root = Tk() leds.on() cv = Canvas(root, width = 600, height = 570, bg = 'white') c1 = cv.create_rectangle(150,10,450,100-40, outline ='white', fill ='pink' ) c7 = cv.create_rectangle(400,100-40,450,300-40, outline ='white', fill ='pink' ) c6 = cv.create_rectangle(400,350-40,450,550-40, outline ='white', fill ='pink' ) c3 = cv.create_rectangle(150,600-40,450,550-40, outline ='white', fill ='pink' ) c5 = cv.create_rectangle(150,350-40,200,550-40, outline ='white', fill ='pink' ) c4 = cv.create_rectangle(150,100-40,200,300-40, outline ='white', fill ='pink' ) c2 = cv.create_rectangle(150,350-40,450,300-40, outline ='white', fill ='pink' ) c8 = drawCircle(cv,510,570-40,30, outline = 'white', fill = 'pink' ) cv.bind('<ButtonRelease-1>',grab) cv.pack() t = Text(root, height = 1)#设置高度为1行高度 t.pack() v = StringVar() Label(root, textvariable=v).pack() v.set("New Text!") root.mainloop() |