您的位置:首页 > 编程语言 > Python开发

some tips about python Six

2017-10-06 15:38 381 查看
import tkinter as tk #引入模块

window = tk.Tk() #设置window对象

window.title('my window')

window.geometry('200x200')

l = tk.Label(window,bg = 'yellow',width = 22,text = 'empty')#设置Label对象,宽度是22个字体

l.pack()#显示在window上

def print_selection():#设置函数

        if(var1.get() == 1) & (var2.get() == 0):#进行判断

                l.config(text = 'I love only Python')#对Label对象的text参数进行设置

        elif(var1.get() == 0) & (var2.get() == 1):

                l.config(text = 'I love only C++')

        elif(var1.get() == 0) & (var2.get() == 0):

                l.config(text = 'I do not love either')

        else:

                l.config(text = 'I love both')

var1 = tk.IntVar()#设置tkinter的整型变量

var2 = tk.IntVar()

c1 = tk.Checkbutton(window,text = 'Python',variable = var1,onvalue = 1, offvalue = 0,

                    command = print_selection)#设置tkinter的复选框,设置变量var1,并且选择var1的时候值为1,不选择的时候值为0

c2 = tk.Checkbutton(window,text = 'C++',variable = var2, onvalue = 1, offvalue = 0,

                    command = print_selection)

c1.pack()

c2.pack()

window.mainloop()#window主循环

###############################################################################################################

import tkinter as tk

window = tk.Tk()

window.title('my window')

window.geometry('200x200')

canvas = tk.Canvas(window,bg = 'blue',height = 100, width = 200)#创建画布

image_file = tk.PhotoImage(file='C:\\Users\\liao\\Desktop\\11.gif')#打开图片文件

image = canvas.create_image(0,0,anchor = 'nw',image = image_file)#在画布上创建image

x0,y0,x1,y1 = 50,50,80,80 #设置坐标

line = canvas.create_line(x0,y0,x1,y1) #画直线,从x0,y0到x1,y1

oval = canvas.create_oval(x0,y0,x1,y1,fill = 'red')#创建圆形,颜色填充为红色

arc = canvas.create_arc(x0+30,y0+30,x1+30,y1+30,start = 0, extent = 180)#创建扇形,start表示扇形开始展开的角度,extent表示扇形结束展开的角度

rect = canvas.create_rectangle(100,30,100+20,30+20)#创建正方形

canvas.pack()#放在画布上

def moveit():

        canvas.move(rect,0,2)#移动canvas上的对象tect,横坐标不动,纵坐标每次移动2

b = tk.Button(window, text = 'move',command = moveit).pack()#放在window上

window.mainloop()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: