tkinter学习笔记_04
8、勾选项 checkbutton
import tkinter as tk
root = tk.Tk()
root.title("xxx")
root.geometry('200x100') # 提示框
l = tk.Label(root, bg='yellow', width=20, text='empty') # textvariable 文本变量值
l.pack() # 勾选框
def print_selection(): # Checkbutton不能传值的
if (var1.get() == 1) & (var2.get() == 0):
l.config(text='I love only Python')
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 love only either')
else:
l.config(text='I love both') var1 = tk.IntVar() # 整数的值
var2 = tk.IntVar() # 整数的值
cl = tk.Checkbutton(root, text='python', variable=var1, onvalue=1, offvalue=0,
command=print_selection) # 选定它onvalue 就是1, 不选择就是offvalue就是0
cl2 = tk.Checkbutton(root, text='C++', variable=var2, onvalue=1, offvalue=0,
command=print_selection)
cl.pack()
cl2.pack() root.mainloop()

9、画布 canvas
import tkinter as tk
root = tk.Tk()
root.title("xxx")
root.geometry('800x600') # 画布 bg背景色
canvas = tk.Canvas(root, bg='blue', height=300, width=800) # height高 width宽
# 右上角添加图片
aa = "C:/Users/bj0204/Desktop/TIM图片20180507183242.png"
image_file = tk.PhotoImage(file=aa)
image = canvas.create_image(10,10, anchor='nw', image=image_file) # anchor 方向
# 画斜线
x0,y0,x1,y1 = 50,50,80,80
line = canvas.create_line(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)
# 长方形
rect = canvas.create_rectangle(100,30,100+20,30+20) canvas.pack()
def moveit():
canvas.move(rect, 0 , 2) # 长方形,从x不动,y方向往下移动
b = tk.Button(root, text='move', command=moveit).pack() root.mainloop()

tkinter学习笔记_04的更多相关文章
- Python:GUI之tkinter学习笔记1控件的介绍及使用
相关内容: tkinter的使用 1.模块的导入 2.使用 3.控件介绍 Tk Button Label Frame Toplevel Menu Menubutton Canvas Entry Mes ...
- Python Tkinter学习笔记
介绍 入门实例 显示一个窗口,窗口里面有一个标签,显示文字 import tkinter as tk # 一个顶层窗口的实例(Top Level),也称为根窗口 app = tk.Tk() # 设置窗 ...
- Python:GUI之tkinter学习笔记之messagebox、filedialog
相关内容: messagebox 介绍 使用 filedialog 介绍 使用 首发时间:2018-03-04 22:18 messagebox: 介绍:messagebox是tkinter中的消息框 ...
- Python:GUI之tkinter学习笔记3事件绑定
相关内容: command bind protocol 首发时间:2018-03-04 19:26 command: command是控件中的一个参数,如果使得command=函数,那么点击控件的时候 ...
- Python:GUI之tkinter学习笔记2界面布局显示
相关内容: pack 介绍 常用参数 使用情况 常用函数 grid 介绍 常用参数 使用情况 常用函数 place 介绍 常用参数 使用情况 常用函数 首发时间:2018-03-04 14:20 pa ...
- node学习笔记_04 express相册
学习node用express框架做了一个相册展示及上传功能: 1.没有连接服务器,这里全部是操作文件夹 2.安装上传文件的依赖formidable,npm install --save formida ...
- Python学习笔记_04:Django框架简介
目录 1 什么是Django? 2 Django框架的开发环境搭建 3 Django操作MySql数据库简介 4 功能强大的Django管理工具应用 1 什么是Django? Django是应用于We ...
- tkinter学习笔记_03
6.单选框 Radiobutton import tkinter as tk root = tk.Tk() root.title("xxx") root.geometry('2 ...
- tkinter学习笔记_06
12.弹窗 messagebox import tkinter as tk from tkinter import messagebox root = tk.Tk() root.title(" ...
随机推荐
- 树组件——jstree使用
本文记录的只是我自己当时的代码,每行的注释很清楚了,你自己可以做相应变通 一.使用前提: 1.下载jstree依赖包 2.相关页面引入样式["jstree/themes/default/st ...
- [USACO06FEB] Stall Reservations 贪心
[USACO06FEB] Stall Reservations 贪心 \(n\)头牛,每头牛占用时间区间\([l_i,r_i]\),一个牛棚每个时间点只能被一头牛占用,问最少新建多少个牛棚,并且每头牛 ...
- nodejs之mysql查询
示例代码中的mysql版本 2.14.1 参考代码 /** * 测试mysql连接 */ var mysql = require('mysql'); var connection = mysql.cr ...
- Android Studio3.0的下载及其安装详解加eclipse下载安装配置jdk9
关注我,每天都有优质技术文章推送,工作,学习累了的时候放松一下自己. 本篇文章同步微信公众号 欢迎大家关注我的微信公众号:「醉翁猫咪」 今天我们来讲解如何下载android studio 3.0及其 ...
- react的3种组件
推荐阅读:https://www.jianshu.com/p/2726b8654989 1. createClass 已不推荐使用,这里不再多讲.但你仍需要了解它,因为你可能会接触到一些旧项目,或者一 ...
- 基于python的学生管理系统(含数据库版本)
这次支持连接到后台的数据库,直接和数据库进行交互,实现基本的增删查改 #!/usr/bin/python3 # coding=utf-8 """ ************ ...
- tf.matmul()报错expected scalar type Float but found Double
tf.matmul(a,b)将矩阵a乘以矩阵b,生成a * b,这里的a,b要有相同的数据类型,否则会因为数据类型不匹配而出错. 如果出错,请看是前后分别是什么类型的,然后把数据类型进行转换.
- 算法名称 Alias Method
public class AliasMethod { /* The probability and alias tables. */ private int[] _alias; private dou ...
- implement a list using Rust
Rust果然比較複雜,在經歷了n次compile fail,終于寫成了一個 list 難點: 對Rc<>的用法不熟悉.對borrow checker不夠熟悉 有些寫法可能還不是最短的 us ...
- 使用create-react-app遇到问题解决方案汇总
使用create-react-app时遇到Module not found问题 转 https://blog.csdn.net/wkq_1212/article/details/90291558 本来 ...