当前位置:网站首页>Tkinter学习笔记(四)
Tkinter学习笔记(四)
2022-06-11 21:52:00 【CHRN晨】
tix和ttk控件
介绍
tix库提供了tk库缺失的常用小控件,如hlist控件,combobox控件,control控件和各种可滚动的小控件,借助tix超级控件可以设计出更加美观的应用程序。
ttk提供了一种与平台无关的窗口工具包
ttk.NoteBook控件
import tkinter as tk
from tkinter import ttk
root=tk.Tk()
root.title('主窗口')
root.geometry('400x300+200+200')
frame=ttk.LabelFrame(root,text='ttk.labelframe',width=200,height=100)
frame.pack(expand=1,fill='both')
#创建notebook
tab=ttk.Notebook(frame)
#增加新选项卡
tab1=ttk.Frame(tab)
tab.add(tab1,text='信息窗')#把新的选项卡添加到notebook
tab2=ttk.Frame(tab)
tab.add(tab2,text='综合分析')#把新的选项卡添加到notebook
tab3=ttk.Frame(tab)
tab.add(tab3,text='技术分析')#把新的选项卡添加到notebook
tab4=ttk.Frame(tab)
tab.add(tab4,text='编写代码')#把新的选项卡添加到notebook
tab5=ttk.Frame(tab)
tab.add(tab5,text='模拟回测')#把新的选项卡添加到notebook
tab6=ttk.Frame(tab)
tab.add(tab6,text='双色球')#把新的选项卡添加到notebook
tab7=ttk.Frame(tab)
tab.add(tab7,text='大乐透')#把新的选项卡添加到notebook
tab.pack(expand=1,fill='both')
tab.select(tab4)#选择tab4
root.mainloop()

ttk.Treeview控件
import tkinter as tk
from tkinter import ttk
root=tk.Tk()
root.title('ttk.TreeView演示')
root.geometry('600x500+200+200')
tree=ttk.Treeview(root,height=10)
#""表示根节点,text显示文本,values是隐藏的值
a=tree.insert("",0,"指标",text="指标",values=("1"),open=True)
a1=tree.insert(a,0,"技术指标",text="技术指标",values=("2"))
a2=tree.insert(a,1,"交易系统",text="交易系统",values=("3"))
a3=tree.insert(a,2,"条件选股",text="条件选股",values=("4"))
a4=tree.insert(a,3,"K线",text="K线",values=("5"))
b=tree.insert("",1,"工具",text='工具',values=("6"),open=True)
b1=tree.insert(b,0,"系统设置",text='系统设置',values=("7"))
b2=tree.insert(b,0,"指标排序",text='指标排序',values=("8"))
tree.pack(fill=tk.X)
tree.selection_set("指标")
#show表示指定那些元素树的显示
tree2=ttk.Treeview(root,columns=('col1','col2','col3'),show="headings")
#修改选项制定了
tree2.column('col1',width=100,anchor='center')
tree2.column('col2',width=100,anchor='center')
tree2.column('col3',width=100,anchor='center')
#修改标题选项指定列
tree2.heading('col1',text='股票代码')
tree2.heading('col2',text='日期')
tree2.heading('col3',text='时间')
def click(event):
item=tree2.selection()[0]
print('you click on',tree2.item(item,"values"))
for i in range(10):
tree2.insert("",i,values=('60007','2021年1月8日','11:1'+str(i)))
#双击左键触发事件
tree2.bind("<Double-1>",click)
tree2.pack(fill=tk.X)
root.mainloop()
#9,10


form表格几何管理器
import tkinter as tk
from tkinter import ttk
from tkinter import tix
#导入tkinter常量,w
from tkinter.constants import *
root=tix.Tk()
width=300
height=200
x=150
y=150
root.geometry('{}x{}+{}+{}'.format(width,height,x,y))
root.title('tix的form布局')
a=tk.Label(root,text='aaa',relief=tix.SUNKEN,bd=1)
#当right,bottom为none时,控件w为自动宽度
a.form(top=50,left=50,right=None,bottom=None)
b=ttk.Label(root,text='bbb')
b.place(x=50,y=100)
c=tix.Label(root,text='ccc',relief=tix.SUNKEN,bd=1)
c.form(top='%30',left='%50')
#当right=-1时表示w的右边到父控件的右边框
d=tix.Label(root,text='ddd',relief=tix.SUNKEN,bd=1)
d.form(left='%50',top=c,bottom=-1)
root.mainloop()
#11

tix.Balloon气球窗口控件
tix.Ballon气球控件可以为其他控件提供帮助,当用户将光标移动
到已绑定该控件的窗口中,屏幕就显示一个带有描述性消息的小型弹出式窗口。
import tkinter.tix as tix
from tkinter.constants import *
event=0
def Run(root):
balloon=DemoBalloon(root)
balloon.mainloop()
balloon.destroy()
class DemoBalloon:
def __init__(self,w):
self.root=w
self.exit=-1
#绑定系统级别的事件
z=w.winfo_toplevel()
z.wm_protocol("WM_DELETE_WINDOW",lambda self=self: self.quitcmd())
z.title('tix.balloon演示')
status=tix.Label(w,width=40,relief=tix.SUNKEN,bd=1)
status.pack(side=tix.BOTTOM,fill=tix.Y,padx=1,pady=1)
#建立两个tix按钮
button1=tix.Button(w,text='关闭窗口',command=self.quitcmd)
button2=tix.Button(w,text='销毁按钮',command=w.destroy)
button1.pack(side=tix.TOP,expand=1)
button2.pack(side=tix.TOP,expand=1)
#建立tixballon
b=tix.Balloon(w,statusbar=status)
b.bind_widget(button1,balloonmsg='关闭',statusmsg='按下这个按钮,关闭窗口')
b.bind_widget(button2,balloonmsg='删除',statusmsg='按下这个按钮,删除按钮')
def quitcmd(self):
self.exit=0
def mainloop(self):
a=1
while self.exit<0 and a>0:
a=self.root.tk.dooneevent(event)
def destroy(self):
self.root.destroy()
if __name__=='__main__':
root=tix.Tk()
Run(root)
#12

tix.ButtonBox按钮框控件
tix.ButtonBox按钮框控件可以添加一下按钮,如“OK”,“cancel”等
tix.combobox组合框控件
用户可以通过链入条目子组件或从列表框子选择组件中选择一个选项。
tix.control控制窗口组件
用户可以通过按上下两个箭头按钮或直接输入数值来调整数值,新值将根据用户定义的上限和下限进行检查。
边栏推荐
- The shortcomings of the "big model" and the strengths of the "knowledge map"
- 继承的所有特征
- Zhanrui IOT chip 8910dm is certified by Deutsche Telekom
- 206.反转链表
- Learning bit segment (1)
- 超標量處理器設計 姚永斌 第2章 Cache --2.4 小節摘錄
- inner join执行计划变了
- Conception du Processeur superscalaire Yao yongbin chapitre 2 cache - - sous - section 2.4 extrait
- 【LeetCode】11. Container with the most water
- 6.项目上线
猜你喜欢

科普 | NFT的类型有哪些(上)

超标量处理器设计 姚永斌 第2章 Cache --2.4 小节摘录
![[niuke.com] ky41 put apples](/img/55/cc246aed1438fdd245530beb7574f0.jpg)
[niuke.com] ky41 put apples

打印机无法打印测试页是什么原因

How to use RPA robot to start the first step of digital transformation of freight forwarding industry?

Cdr2022 serial number coreldraw2022 green key
![[niuke.com] dp31 [template] complete Backpack](/img/81/5f35a58c48f05a5b4b6bdc106f5da0.jpg)
[niuke.com] dp31 [template] complete Backpack

Optimization of quick sort

Superscalar processor design yaoyongbin Chapter 2 cache -- Excerpt from subsection 2.2

类和对象(2)
随机推荐
R语言书籍学习03 《深入浅出R语言数据分析》-第十章 关联规则 第十一章 随机森林
Endnotex9 introduction and basic tutorial instructions
Internet of things development practice 18 scenario linkage: how does an intelligent light perceive light? (I) (learning notes)
6.项目上线
LaTex实战笔记 3-宏包与控制命令
C语言实现八种排序(3)
Leetcode - 第2天
One question of the day - delete duplicates of the ordered array
How to view the installation date of the win system
EndnoteX9簡介及基本教程使用說明
3.3 测试模块的命名规则
Master of a famous school has been working hard for 5 years. AI has no paper. How can the tutor free range?
67. binary sum
67. 二进制求和
每日一题 -- 验证回文串
The upcoming launch of the industry's first retail digital innovation white paper unlocks the secret of full link digital success
Summary of common paging methods
MySQL事务简介
Classes and objects (1)
不使用加减乘除做加法