How to change the font of Action Bar's Option Menu Items Title?
Inside in styles.xml
add below code
<item name="android:actionMenuTextAppearance">@style/MyActionBar.MenuTextStyle</item>
so the styles.xml look like this.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:itemBackground">@color/skyBlue</item>
<item name="android:textStyle">bold</item>
<item name="android:actionMenuTextAppearance">@style/MyActionBar.MenuTextStyle</item>
</style>
<style name="MyActionBar.MenuTextStyle" parent="Theme.AppCompat">
<item name="actionMenuTextColor">@color/white</item>
<item name="android:actionMenuTextColor">@color/white</item>
</style>
and then create style for MyActionBar.MenuTextStyle
and change the TextView
property as you wish.
Note : You can only use
custom fonts
viaJava code
, not through
layoutXML
orstyles/themes
.
for more detail visit this : Set specific font in a styles.xml
Tkinter OptionMenu: How to configure font size of drop down list?
You have to use the nametowidget()
method to get the widget object corresponding to the dropdown menu widget, then set its configuration.
Here's a runnable example:
import tkinter as tk
import tkinter.font as tkFont
root = tk.Tk()
root.geometry('300x200')
helv36 = tkFont.Font(family='Helvetica', size=36)
options = 'eggs spam toast'.split()
selected = tk.StringVar(root, value=options[0])
choose_test = tk.OptionMenu(root, selected, *options)
choose_test.config(font=helv36) # set the button font
helv20 = tkFont.Font(family='Helvetica', size=20)
menu = root.nametowidget(choose_test.menuname) # Get menu widget.
menu.config(font=helv20) # Set the dropdown menu's font
choose_test.grid(row=0, column=0, sticky='nsew')
root.mainloop()
Here's are two screenshots showing the default vs modified dropdown menu text sizes:
Is it possible to change the font of every menu option in Tkinter
Yes, it is possible to change the font of each item in an option menu but make sure that font is compatible with Tkinter otherwise it won't show up, you can check all the fonts compatible with Tkinter by
import tkinter as tk
import tkinter.font as font
root = tk.Tk()
print(list(font.families()))
Now to change each font in the optionmenu we use entryconfigure
method of the menu linked with the optionmenu widget can be accessed by its object (op['menu']
). The menu of optionmenu has all the options of a Tkinter Menu.
Take a look at this example.
import tkinter as tk
import tkinter.font as font
root = tk.Tk()
root.geometry('200x150')
var = tk.StringVar()
op = tk.OptionMenu(root, var, *font.families())
op.pack(pady=20)
lb = tk.Label(root, textvariable=var)
lb.pack()
for item in range(0, int(op['menu'].index('end'))):
op['menu'].entryconfig(item, font=font.Font(family=font.families()[item]))
var.trace('w', lambda *a: lb.config(font=op['menu'].entrycget(var.get(),'font')))
root.mainloop()
Related Topics
Popupwindow - Dismiss When Clicked Outside
Android - Save/Restore Fragment State
Show Icon in Actionbar/Toolbar with Appcompat-V7 21
How to Re-Sign an .Apk with a Different Certificate Than What It Came With
Proguard Hell - Can't Find Referenced Class
Compile with Proguard Gives Simexception: "Local Variable Type Mismatch"
Differencebetween Android Margin Start/End and Right/Left
How to Call Wi-Fi Settings Screen from My Application Using Android
Passing Argument to Dialogfragment
Sqlite Android Database Cursor Window Allocation of 2048 Kb Failed
Download Files and Store Them Locally with Phonegap/Jquery Mobile Android and iOS Apps
Movecamera with Cameraupdatefactory.Newlatlngbounds Crashes
How to Build Signed APK from Android Studio for Flutter
Programmatically Getting the Gateway and Subnet Mask Details
Programmatically Relaunch/Recreate an Activity
Programmatically Adding Tablerow to Tablelayout Not Working
Android - How to Get the Processname or Packagename by Using Pid
How to Open or Simulate a Click on an Android Preference, Created with Xml, Programmatically