[雪峰磁针石博客]python tkinter图形工具样式作业

简介:

使用tkinter绘制如下窗口

图片.png

参考资料

代码

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 技术支持:https://www.jianshu.com/u/69f40328d4f0 
# 技术支持 https://china-testing.github.io/
# https://github.com/china-testing/python-api-tesing/blob/master/practices/tk/tk4.py
# 项目实战讨论QQ群630011153 144081101
# CreateDate: 2018-12-02

import tkinter as tk
root = tk.Tk()
root.configure(background='#4D4D4D')  #top level styling

# connecting to the external styling optionDB.txt
root.option_readfile('optionDB.txt')

#widget specific styling
text = tk.Text(
    root,
    background='#101010',
    foreground="#D6D6D6",
    borderwidth=18,
    relief='sunken',
    width=17,
    height=5)
text.insert(
    tk.END,
    "Style is knowing who you are,what you want to say, and not giving a damn."
)
text.grid(row=0, column=0, columnspan=6, padx=5, pady=5)

# all the below widgets derive their styling from optionDB.txt file
tk.Button(root, text='*').grid(row=1, column=1)
tk.Button(root, text='^').grid(row=1, column=2)
tk.Button(root, text='#').grid(row=1, column=3)
tk.Button(root, text='<').grid(row=2, column=1)
tk.Button(
    root, text='OK', cursor='target').grid(
        row=2, column=2)  #changing cursor style
tk.Button(root, text='>').grid(row=2, column=3)
tk.Button(root, text='+').grid(row=3, column=1)
tk.Button(root, text='v').grid(row=3, column=2)
tk.Button(root, text='-').grid(row=3, column=3)
for i in range(10):
  tk.Button(
      root, text=str(i)).grid(
          column=3 if i % 3 == 0 else (1 if i % 3 == 1 else 2),
          row=4 if i <= 3 else (5 if i <= 6 else 6))

root.mainloop()

可以使用十六进制颜色代码为红色(r),绿色(g)和蓝色(b)的比例指定颜色。常用的表示是#rgb(4位),#rrggbb(8位)和#rrrgggbbb(12位)。

例如,#ff是白色,#000000是黑色,#f00是红色(R = 0xf,G = 0x0,
B = 0x0),#00ff00为绿色(R = 0x00,G = 0xff,B = 0x00),#000000fff为蓝色(R = 0x000,G = 0x000,B = 0xfff)。

或者,Tkinter提供标准颜色名称的映射。有关预定义命名颜色的列表,请访问http://wiki.tcl.tk/37701http://wiki.tcl.tk/16166

相关文章
|
5月前
|
存储 缓存 测试技术
理解Python装饰器:简化代码的强大工具
理解Python装饰器:简化代码的强大工具
|
6月前
|
程序员 测试技术 开发者
Python装饰器:简化代码的强大工具
Python装饰器:简化代码的强大工具
264 92
|
5月前
|
机器学习/深度学习 编解码 Python
Python图片上采样工具 - RealESRGANer
Real-ESRGAN基于深度学习实现图像超分辨率放大,有效改善传统PIL缩放的模糊问题。支持多种模型版本,推荐使用魔搭社区提供的预训练模型,适用于将小图高质量放大至大图,放大倍率越低效果越佳。
425 3
|
5月前
|
算法 安全 数据安全/隐私保护
Python随机数函数全解析:5个核心工具的实战指南
Python的random模块不仅包含基础的随机数生成函数,还提供了如randint()、choice()、shuffle()和sample()等实用工具,适用于游戏开发、密码学、统计模拟等多个领域。本文深入解析这些函数的用法、底层原理及最佳实践,帮助开发者高效利用随机数,提升代码质量与安全性。
1005 0
|
5月前
|
数据采集 机器学习/深度学习 人工智能
Python:现代编程的首选语言
Python:现代编程的首选语言
511 102
|
5月前
|
数据采集 机器学习/深度学习 算法框架/工具
Python:现代编程的瑞士军刀
Python:现代编程的瑞士军刀
398 104

推荐镜像

更多