0
from tkinter import *
import tkinter.messagebox
from tkinter import filedialog
from tkinter import ttk
from ttkthemes import themed_tk as tk
import os

root = tk.ThemedTk()
root.get_themes()
root.set_theme("plastik")

# Frames on main window
topframe = Frame(root)
topframe.pack(padx = 10, pady = 10)

nameLable = ttk.Label(topframe, text = "Patient Name")
nameLable.pack(side = LEFT, padx = 5)
patientName = ttk.Entry(topframe, width = 40)
patientName.pack(side = LEFT, padx = 5)

ageLabel = ttk.Label(topframe, text = "Patient Age")
ageLabel.pack(side = LEFT, padx = 5)
patientAge = Entry(topframe)
patientAge.pack(side = LEFT, padx = 5)


genderLabel = ttk.Label(topframe, text = "Select Gender")
genderLabel.pack(side = LEFT, padx = 5)

tkvar = StringVar(root)
choices = {'Select', 'Male', 'Female'}
tkvar.set('Select')
genderMenu = ttk.OptionMenu(topframe, tkvar, *choices)
genderMenu.pack(padx = 5)

leftframe = Frame(root)
leftframe.pack()

left_bottomframe = Frame(leftframe)
left_bottomframe.pack()

rightframe = Frame(root)
rightframe.pack()

right_topframe = Frame(rightframe)
right_topframe.pack()

right_bottomframe = Frame(rightframe)
right_bottomframe.pack()


root.mainloop()

I am new to ttk themes tried to find the issue on google and stack overflow but didn't find the solution. There are some similar issues but not this issue in particular, that is why I am asking this question.

This is the code where the OptionMenu works just fine in normal case but when it is written as ttk.OptionMenu the default select option changes randomly.

How to fix this issue?

martineau
  • 119,623
  • 25
  • 170
  • 301
  • You appear to be using some third-party library because there's nothing named `ttk.OptionMenu` or `ttkthemes` in the standard library. Please specify thing in your question. – martineau Dec 01 '19 at 05:12
  • So is there other way to change the option menu theme and fix the default set value – Debanjan Karmakar Dec 01 '19 at 06:40
  • 2
    Change `choices` to a list. – Kenly Dec 01 '19 at 10:48
  • @martineau Read about [ttkthemes](https://github.com/TkinterEP/ttkthemes) – stovfl Dec 01 '19 at 11:21
  • @stovfl: Thx. Still doesn't explain what a `ttk.OptionMenu` is. Regardless, @Kenly is probably right wrt to the cause of the random option changes. – martineau Dec 01 '19 at 15:50
  • 1
    @martineau: `ttk.OptionMenu` is new in `3.7`, see current [Python version 3.9.0](https://github.com/python/cpython/blob/master/Lib/tkinter/ttk.py#L1600). – stovfl Dec 01 '19 at 16:04
  • Does this answer your question? [tkinter optionmenu first option vanishes](https://stackoverflow.com/questions/19138534/tkinter-optionmenu-first-option-vanishes) – j_4321 Jan 08 '20 at 10:43

0 Answers0