当前位置:网站首页>Tkinter study notes (IV)

Tkinter study notes (IV)

2022-06-11 22:07:00 Chrn morning

Introduce

tix The library provides tk Common gizmos missing from the library , Such as hlist Control ,combobox Control ,control Control and various scrollable gizmos , With the help of tix Super controls can design more beautiful applications .
ttk Provides a platform independent window toolkit

ttk.NoteBook Control

import tkinter as tk
from tkinter import ttk
root=tk.Tk()
root.title(' main window ')
root.geometry('400x300+200+200')
frame=ttk.LabelFrame(root,text='ttk.labelframe',width=200,height=100)
frame.pack(expand=1,fill='both')
# establish notebook
tab=ttk.Notebook(frame)
# Add new tab 
tab1=ttk.Frame(tab)
tab.add(tab1,text=' section in a publication or regular feature on radio or television dedicated to disseminating various types of information ')# Add a new tab to notebook
tab2=ttk.Frame(tab)
tab.add(tab2,text=' Comprehensive analysis of ')# Add a new tab to notebook

tab3=ttk.Frame(tab)
tab.add(tab3,text=' Technical analysis ')# Add a new tab to notebook

tab4=ttk.Frame(tab)
tab.add(tab4,text=' Write code ')# Add a new tab to notebook

tab5=ttk.Frame(tab)
tab.add(tab5,text=' Simulation back test ')# Add a new tab to notebook

tab6=ttk.Frame(tab)
tab.add(tab6,text=' Bicolor ')# Add a new tab to notebook

tab7=ttk.Frame(tab)
tab.add(tab7,text=' Big lotto ')# Add a new tab to notebook
tab.pack(expand=1,fill='both')

tab.select(tab4)# choice tab4
root.mainloop()

 Insert picture description here

ttk.Treeview Control

import tkinter as tk
from tkinter import ttk
root=tk.Tk()
root.title('ttk.TreeView demonstration ')
root.geometry('600x500+200+200')
tree=ttk.Treeview(root,height=10)
#"" Represents the root node ,text Show text ,values Is a hidden value 
a=tree.insert("",0," indicators ",text=" indicators ",values=("1"),open=True)
a1=tree.insert(a,0," Technical indicators ",text=" Technical indicators ",values=("2"))
a2=tree.insert(a,1," trading system ",text=" trading system ",values=("3"))
a3=tree.insert(a,2," Conditional stock selection ",text=" Conditional stock selection ",values=("4"))
a4=tree.insert(a,3,"K Line ",text="K Line ",values=("5"))

b=tree.insert("",1," Tools ",text=' Tools ',values=("6"),open=True)
b1=tree.insert(b,0," System settings ",text=' System settings ',values=("7"))
b2=tree.insert(b,0," Index ranking ",text=' Index ranking ',values=("8"))
tree.pack(fill=tk.X)
tree.selection_set(" indicators ")
#show Specifies the display of those element trees 
tree2=ttk.Treeview(root,columns=('col1','col2','col3'),show="headings")
# Modify the options to make 
tree2.column('col1',width=100,anchor='center')
tree2.column('col2',width=100,anchor='center')
tree2.column('col3',width=100,anchor='center')
# Modify the title option to specify the column 
tree2.heading('col1',text=' Stock code ')
tree2.heading('col2',text=' date ')
tree2.heading('col3',text=' Time ')

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 year 1 month 8 Japan ','11:1'+str(i)))
# Double click the left button to trigger the event 
tree2.bind("<Double-1>",click)

tree2.pack(fill=tk.X)
root.mainloop()
#9,10

 Insert picture description here
 Insert picture description here

form Table geometry Manager

import tkinter as tk
from tkinter import ttk
from tkinter import tix
# Import tkinter Constant ,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 Of form Layout ')
a=tk.Label(root,text='aaa',relief=tix.SUNKEN,bd=1)
# When right,bottom by none when , Control w Is the automatic width 
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')

# When right=-1 It means w To the right border of the parent control 
d=tix.Label(root,text='ddd',relief=tix.SUNKEN,bd=1)
d.form(left='%50',top=c,bottom=-1)

root.mainloop()
#11

 Insert picture description here

tix.Balloon Balloon window control

tix.Ballon Balloon controls can help other controls , When the user moves the cursor
To the window that is bound to the control , The screen displays a small pop-up window with a descriptive message .

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
        # Bind system level events 
        z=w.winfo_toplevel()
        z.wm_protocol("WM_DELETE_WINDOW",lambda self=self: self.quitcmd())
        z.title('tix.balloon demonstration ')
        status=tix.Label(w,width=40,relief=tix.SUNKEN,bd=1)
        status.pack(side=tix.BOTTOM,fill=tix.Y,padx=1,pady=1)
        # Set up two tix Button 
        button1=tix.Button(w,text=' close window ',command=self.quitcmd)
        button2=tix.Button(w,text=' Destroy button ',command=w.destroy)
        button1.pack(side=tix.TOP,expand=1)
        button2.pack(side=tix.TOP,expand=1)
        # establish tixballon
        b=tix.Balloon(w,statusbar=status)
        b.bind_widget(button1,balloonmsg=' close ',statusmsg=' Press this button , close window ')
        b.bind_widget(button2,balloonmsg=' Delete ',statusmsg=' Press this button , Delete button ')
    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

 Insert picture description here

tix.ButtonBox Button box control

tix.ButtonBox The button box control can add a button , Such as “OK”,“cancel” etc.

tix.combobox Combo box control

The user can select an option by chaining in the item sub component or selecting from the list box sub component .

tix.control Control window components

The user can adjust the value by pressing the up and down arrow buttons or directly entering the value , The new value will be checked against the user-defined upper and lower limits .

原网站

版权声明
本文为[Chrn morning]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206112152200022.html