admin管理员组文章数量:1405385
I am trying to display unicode characters in a Combobox using Tkinter. For this example, I don't fill a drop-down list, I only use the entry field. I already watched stack overflow topics:
- how to use unicode and special chareacters characters in Tkinter
- how to specify and view high-numbered unicode characters I did not find examples in relation with the following phenomenon:
assigning the string 'hello' to the combo: (*) the button displays the wanted glyph tetragram the combobox displays 'Hello'
assigning the same high-numbered unicode to the button and the combobox: (**) the button and the combobox display the wanted glyph tetragrams
assigning a different high-numbered unicode to the button and the combobox: (***) the button displays the wanted glyph tetragram the combobox displays a glyph indicating an unknown symbol
'''
import tkinter as tk
from tkinter import *
from tkinter import ttk, font
import unicodedata
win = Tk()
win.geometry("270x700")
cbstyle = ttk.Style()
btstyle = ttk.Style()
btstyle.configure('styBut.TButton', font=('DejaVu Sans', 20))
cbstyle.configure('styComb.TCombobox', font=('DejaVu Sans', 20))
strVaButton = tk.StringVar()
strVaCombo = tk.StringVar()
strVaButton.set(u'\U0001D354')
#strVaCombo.set(u'\U0001D354') (**)
strVaCombo.set(u'\U0001D320') (***)
#strVaCombo.set('Hello !') (*)
print(strVaButton.get())
print(type(strVaButton.get()))
print(unicodedata.name(strVaButton.get()))
#print(unicodedata.name(strVaCombo.get()))
theBut = ttk.Button(win, textvariable = strVaButton,style="styBut.TButton")
theComb = ttk.Combobox(win, textvariable = strVaCombo,style="styComb.TCombobox")
theBut.pack()
theComb.pack()
win.mainloop()'''
I am trying to display unicode characters in a Combobox using Tkinter. For this example, I don't fill a drop-down list, I only use the entry field. I already watched stack overflow topics:
- how to use unicode and special chareacters characters in Tkinter
- how to specify and view high-numbered unicode characters I did not find examples in relation with the following phenomenon:
assigning the string 'hello' to the combo: (*) the button displays the wanted glyph tetragram the combobox displays 'Hello'
assigning the same high-numbered unicode to the button and the combobox: (**) the button and the combobox display the wanted glyph tetragrams
assigning a different high-numbered unicode to the button and the combobox: (***) the button displays the wanted glyph tetragram the combobox displays a glyph indicating an unknown symbol
'''
import tkinter as tk
from tkinter import *
from tkinter import ttk, font
import unicodedata
win = Tk()
win.geometry("270x700")
cbstyle = ttk.Style()
btstyle = ttk.Style()
btstyle.configure('styBut.TButton', font=('DejaVu Sans', 20))
cbstyle.configure('styComb.TCombobox', font=('DejaVu Sans', 20))
strVaButton = tk.StringVar()
strVaCombo = tk.StringVar()
strVaButton.set(u'\U0001D354')
#strVaCombo.set(u'\U0001D354') (**)
strVaCombo.set(u'\U0001D320') (***)
#strVaCombo.set('Hello !') (*)
print(strVaButton.get())
print(type(strVaButton.get()))
print(unicodedata.name(strVaButton.get()))
#print(unicodedata.name(strVaCombo.get()))
theBut = ttk.Button(win, textvariable = strVaButton,style="styBut.TButton")
theComb = ttk.Combobox(win, textvariable = strVaCombo,style="styComb.TCombobox")
theBut.pack()
theComb.pack()
win.mainloop()'''
Share
Improve this question
asked Mar 22 at 9:35
JaHeJaHe
12 bronze badges
2
|
1 Answer
Reset to default 0win.option_add('*TCombobox*font', text_fontu)
will affect the font for all the TCombobox
widgets defined in the application. However, new TCombobox
defaults could be overwritten for any particular TCombobox
while defining it by ttk.Combobox
:
import tkinter as tk
import tkinter.ttk as ttk
from tkinter import font
win = tk.Tk()
win.geometry("270x300")
text_fontb = ('DejaVu Sans', 20)
text_fontu = ('Unifont Upper', 20)
text_fontf = ('DejaVu Serif Condensed', 20)
style = ttk.Style()
style.configure('Stybut.TButton', font=text_fontb, width=12)
strVaButton = tk.StringVar(); strVaButton.set(u'\U0001D354 Sans')
strVaCombou = tk.StringVar(); strVaCombou.set(u'\U0001D320 Unifont')
strVaCombof = tk.StringVar(); strVaCombof.set(u'\U0001D320 Serif')
# set defaults for all `TCombobox` widgets
win.option_add('*TCombobox*font', text_fontu)
win.option_add('*TCombobox*width', 12)
theButon = ttk.Button (win, textvariable=strVaButton, style="Stybut.TButton")
theCombu = ttk.Combobox(win, textvariable=strVaCombou)
theCombf = ttk.Combobox(win, textvariable=strVaCombof, font=text_fontf, width=8)
theButon.pack()
theCombu.pack()
theCombf.pack()
win.mainloop()
Explanation: in above code snippet,
theCombu = ttk.Combobox(win, textvariable=strVaCombou)
definestheCombu
Combobox usingTCombobox
default options declared inwin.option_add
, whiletheCombf = ttk.Combobox(win, textvariable=strVaCombof, font=text_fontf, width=8)
definestheCombf
Combobox determining desired options (font
andwidth
in this case) explicitly.
Result:
本文标签: buttonUnexpected behaviour of tkinter combobox with highnumbered UnicodeStack Overflow
版权声明:本文标题:button - Unexpected behaviour of tkinter combobox with high-numbered Unicode - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744320144a2600456.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
win.option_add('*TCombobox*font', text_font)
beforetheComb = ttk.Combobox(…)
(providingtext_font = ('DejaVu Sans', 20)
, of course)? – JosefZ Commented Mar 22 at 17:11