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()
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()
相关文章推荐
- some tips about python Two
- Some tips about argument in python
- Some tips about Control Flow in Python
- some tips about python Four
- Some tips about python
- Some tips about Class in Python
- some tips about python One
- some tips about python Three
- some tips about python default value....
- some tips about python
- Some tips about python Seven
- Some basic tips about 'git stash'
- Python 数据处理的 Some tips --- 索引
- some tips about shell variables
- Some tips about crawling large external data with bcs connector
- Share some tips about android develop(一)
- Some Tips about Interbase
- About GNIT some tips
- Some Tips and Tricks about Qt
- Some tips about the life cycle of Maya thread pool