I'm creating a Windows app UI in Python.The module used is Tkinter.
By default, the radio button display is very small, so I want to make it bigger, but I don't know what to do.
If anyone knows, could you give me some advice?
import tkinter ask
import ctypes
class showUI:
def__init__(self):
font_general=('Meiryo UI', '14', 'normal')
try:
ctypes.windll.shcore.SetProcessDpiAwareness (True)
except:
pass
root=tk.Tk()
root.title('sample')
root.geometry ('500x100')
select = tk.IntVar()
select.set(0)
radio0=tk.Radiobutton(
root,
variable=select,
value = 0,
text = 'Radio A',
font=font_general
)
radio1 = tk.Radiobutton(
root,
variable=select,
value = 1,
text = 'Radio B',
font=font_general
)
radio0.place (relx=0.1, rely=0.05)
radio1.place(relx=0.5, rely=0.05)
root.mainloop()
self.select=select.get()
root.destroy()
if__name__=='__main__':
showUI()
By applying these articles, we were able to switch to images of any size prepared in advance.
How do you change ttk.Radiobutton circuit/diamond?
Can't change button font size intkinter
tkinter.(ttk.)Radiobutton [Radio Button Widget]
import tkinter ask
from tkinter import ttk####ttk Added
import ctypes
class showUI:
def__init__(self):
try:
ctypes.windll.shcore.SetProcessDpiAwareness (True)
except:
pass
root=tk.Tk()
root.title('sample')
root.geometry ('500x100')
select = tk.IntVar()
select.set(0)
#### Off/On Image Read and Style to Radio Button
style=ttk.Style(root)
with open('Off.png', 'rb') as f:
data_unselected=f.read()
img_unselected=tk.PhotoImage("radiobutton_unselected", master=root, data=data_unselected)
with open('On.png', 'rb') as f:
data_selected=f.read()
img_selected=tk.PhotoImage("radiobutton_selected", master=root, data=data_selected)
style.element_create('custom.indicator', 'image', 'radiobutton_unselected',
('selected', '!disabled', 'radiobutton_selected'))
style.layout(
'TRadiobutton',
[('Radiobutton.padding',
{'sticky':'nswe',
'children': [('custom.indicator', {'side':'left', 'sticky':'}),
('Radiobutton.focus',
{'side':'left',
'sticky':',
'children': [('Radiobutton.label', {'sticky':'nswe'})]})]})])
### Change to font settings in ttk
style.configure('TRadiobutton', font=('Meiryo UI',14,'normal')
radio0=ttk.Radiobutton (change from ####tk to ttk, change font to style)
root,
variable=select,
value = 0,
text = 'Radio A'
)
radio1 = ttk.Radiobutton (change from ####tk to ttk, change font to style)
root,
variable=select,
value = 1,
text = 'Radio B'
)
radio0.place (relx=0.1, rely=0.05)
radio1.place(relx=0.5, rely=0.05)
root.mainloop()
self.select=select.get()
root.destroy()
if__name__=='__main__':
showUI()
Off Image
On Image
View Results
© 2024 OneMinuteCode. All rights reserved.