Combobox and Entry#
Normal |
Normal |
Disabled |
Disabled |
Invalid |
Entry |
Combo |
Entry |
Combo |
Entry |
In the end combobox looked out of place with its plain down arrow. The down arrow can be reused and entry based on the combobox before it is cropped.
Show/Hide Code 10combo_entry.py
'''
combo text area, used as entry before cropping
made separate entry for invalid
'''
from PIL import Image, ImageDraw, ImageOps
from roundrect import Bi_Base_Rect
from tools import trans
exp = 9 # enlargement, also thickness between rectangles
#d = (exp-1)//2 # displacement
w=26
h=25
radius = 5 # gap size
tab=0
second = '#5D9B90' # (222,247,222)
first = '#A3CCC4' # ~half of border
third = 'white'
dark = '#8b0a50'
light = '#D8137F'
fout = '../images/lime/entry-n.png'
fout2 = '../images/lime/entry-d.png'
fout3 = '../images/lime/entry-i.png'
Bi_Base_Rect(fout,w,h, exp, radius, first, second,third,tab)
img = Image.open(fout)
ImageOps.crop(img,(0,0,radius-2,0)).save('../images/lime/combo-n.png')
img = Image.open(fout)
dimg = img.convert('L')
dimg = dimg.convert('RGBA')
dimg.save(fout2)
trans(dimg,w,h,radius)
dimg.save(fout2)
ImageOps.crop(dimg,(0,0,radius-2,0)).save('../images/lime/combo-d.png')
Bi_Base_Rect(fout3,w,h, exp, radius, light, dark,third,tab)
#trans(w,h,radius,fout3)
Show/Hide Code 10lime_combobox.py
'''
Combobox
Create theme extract for custom widgets, include state selection to view
the result of changing the state using different images and/or different
settings.
Combobox states disabled, readonly;focus, readonly; normal, focus, pressed,
disabled; normal,readonly,active; normal,pressed,active, disabled
'''
from tkinter import Tk, PhotoImage
from tkinter.ttk import Style, Frame, Combobox
from RunState import run_state
root = Tk()
fr = Frame(root)
fr.grid(column=0,row=0,sticky='nsew')
img1 = PhotoImage("combo-n", file='../images/lime/combo-n.png')
img3 = PhotoImage("combo-d", file='../images/lime/combo-d.png')
img7 = PhotoImage("arrowdown-a", file='../images/lime/arrowdown-a.png')
img8 = PhotoImage("arrowdown-d", file='../images/lime/arrowdown-d.png')
img9 = PhotoImage("arrowdown-n", file='../images/lime/arrowdown-n.png')
img10 = PhotoImage("arrowdown-p", file='../images/lime/arrowdown-p.png')
style = Style()
# both theme_create and theme_settings worked
style.theme_create( "yummy", parent="clam", settings={
#style.theme_settings('alt', {
# start of theme extract
"Combobox.field": {"element create":
("image", 'combo-n',
('readonly', 'disabled', 'combo-d'),
#('readonly', 'pressed', 'combo-rp'),
#('readonly', 'focus', 'combo-rf'),
#('readonly', 'combo-rn'),
{'sticky': 'ew', 'border': [4],'padding': 1}
)
},
"Combobox.downarrow": {"element create":
("image", 'arrowdown-n',
('disabled','arrowdown-d'),
('pressed','arrowdown-p'),
('active','arrowdown-a'),
{'sticky': '','border': [1],'padding': 4}
)
}
# end of theme extract - don't forget to add comma at end when inserting
})
style.theme_use('yummy') # 'alt'
widg = Combobox(fr,values=['apple', 'banana', 'orange'])
widg.grid(column=0,row=18,padx=5,pady=5 )
widg1 = Combobox(fr,values=['apple', 'banana', 'orange'])
widg1.grid(column=0,row=19,padx=5,pady=5,sticky='ns')
run_state(fr,widg,widg1)
root.mainloop()
Show/Hide Code 10lime_entry.py
'''
Ensure that the indentations work
Create theme extract for custom widgets, include state selection to view
the result of changing the state using different images and/or different
settings.
Entry states normal, focus; disabled, readonly;focus, readonly; normal, focus;
'''
from tkinter import Tk, PhotoImage, StringVar
from tkinter.ttk import Style, Frame, Entry
from RunState import run_state
root = Tk()
fr = Frame(root)
fr.grid(column=0,row=0,sticky='nsew')
img1 = PhotoImage("entry-n", file='../images/lime/entry-n.png')
img2 = PhotoImage("entry-i", file='../images/lime/entry-i.png')
img3 = PhotoImage("entry-d", file='../images/lime/entry-d.png')
style = Style()
# both theme_create and theme_settings worked
style.theme_create( "yummy", parent="clam", settings={
#style.theme_settings('default', {
# start of theme extract
'Entry.field': {"element create":
('image', "entry-d",
('focus', 'entry-n'),
('!disabled','invalid', 'entry-i'),
('disabled', 'entry-d'),
{'height': 18,'border':4,'padding':[3,4], 'sticky': 'nsew'})}
# end of theme extract - don't forget to add comma at end when inserting
})
style.theme_use('yummy') # 'default'
sv = StringVar()
widg = Entry(fr,textvariable=sv)
widg.grid(column=0,row=18,padx=5,pady=5 )
sv.set('first')
sv1 = StringVar()
widg1 = Entry(fr,textvariable=sv1)
widg1.grid(column=0,row=19,padx=5,pady=5,sticky='ns')
sv1.set('second really really long')
run_state(fr,widg,widg1)
root.mainloop()