Is there anyway to set the individual options in Tkinter to a
particular variable. For example, I have a menu option(code is below)
which has January, February, March and so on, which I would like to
have corresponding values of 01, 02, 03 and so on. Can someone please
tell me how to do that within the context of the code I have below -
or even totally modify it if you must.
Label(self,
text = "Month"
).grid(row = 5, column = 1, sticky = W)
OPTIONS = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"June",
"July",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"]
default_option = StringVar(self)
default_option.set(OPTIONS[0])
self.month_option = OptionMenu(self, default_option, *OPTIONS)
self.month_option.grid(row = 5, column = 2, sticky = W) 2 1561
Chad wrote:
Is there anyway to set the individual options in Tkinter to a
particular variable. For example, I have a menu option(code is below)
which has January, February, March and so on, which I would like to
have corresponding values of 01, 02, 03 and so on. Can someone please
tell me how to do that within the context of the code I have below -
or even totally modify it if you must.
Label(self,
text = "Month"
).grid(row = 5, column = 1, sticky = W)
OPTIONS = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"June",
"July",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"]
default_option = StringVar(self)
default_option.set(OPTIONS[0])
self.month_option = OptionMenu(self, default_option, *OPTIONS)
self.month_option.grid(row = 5, column = 2, sticky = W)
What about using dictionary? For example:
<code>
import Tkinter as Tk
def state():
print OPTIONS[default_option.get()]
root = Tk.Tk()
Tk.Label(root, text="Month").grid(row=1, column=1, sticky=Tk.W)
OPTIONS = dict(Jan=1, Feb=2, Mar=3, Apr=4, May=5, June=6, July=7,
Aug=8, Sep=9, Oct=10, Nov=11, Dec=12)
# or
#OPTIONS = dict(Jan="01", Feb="02", Mar="03", Apr="04", May="05",
June="06", July="07",
# Aug="08", Sep="09", Oct="10", Nov="11", Dec="12")
default_option = Tk.StringVar()
default_option.set("Jan")
month_option = Tk.OptionMenu(root, default_option, *OPTIONS.keys())
month_option.grid(row=1, column=2, sticky=Tk.W)
Tk.Button(root, command=state, text='state').grid(row=2, column=1)
root.mainloop()
</code>
--
HTH,
Rob
Rob Wolfe wrote:
Chad wrote:
>... I have a menu option(code is below).... I would like to have corresponding values of 01, 02, 03 and so on....
What about using dictionary? For example: ....
OPTIONS = dict(Jan=1, Feb=2, Mar=3, Apr=4, May=5, June=6, July=7,
Aug=8, Sep=9, Oct=10, Nov=11, Dec=12)
# or
#OPTIONS = dict(Jan="01", Feb="02", Mar="03", Apr="04", May="05",
June="06", July="07",
# Aug="08", Sep="09", Oct="10", Nov="11", Dec="12")
or
OPTIONS = dict((m, n + 1) for n, m in enumerate(
'Jan Feb Mar Apr May June July Aug Sep Oct Nov Dec'.split()))
--
--Scott David Daniels sc***********@acm.org This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Marc |
last post by:
Hi all,
I was using Tkinter.IntVar() to store values from a large list of
parts that I pulled from a list. This is the code to initialize the
instances:
def initVariables(self):
self.e =...
|
by: Russell E. Owen |
last post by:
I want to support execution of simple user-written scripts in a Tkinter
application. The scripts should be able to wait for data and such
without hanging the GUI (and without having to write the...
|
by: max(01)* |
last post by:
hi people.
when i create a widget, such as a toplevel window, and then i destroy
it, how can i test that it has been destroyed? the problem is that even
after it has been destroyed, the instance...
|
by: William Gill |
last post by:
Working with tkinter, I have a createWidgets() method in a class.
Within createWidgets() I create several StringVars() and
assign them to the textvariable option of several widgets.
Effectively my...
|
by: Tuvas |
last post by:
I know this is probably a very simple question, but I am building a
program that is now at about 2400 lines of code in the main module. I
need to break it up, however, there are certain variables...
|
by: Michael Yanowitz |
last post by:
Hello:
Below I have included a stripped down version of the GUI I am working on.
It contains 2 dialog boxes - one main and one settings. It has the following
problems, probably all related, that...
|
by: Lie |
last post by:
Inspect the following code:
--- start of code ---
import Tkinter as Tk
from Tkconstants import *
root = Tk.Tk()
e1 = Tk.Entry(root, text = 'Hello World')
e2 = Tk.Entry(root, text = 'Hello...
|
by: C Martin |
last post by:
What am I doing wrong in this code? The callback doesn't work from the Entry widget.
##start code
import Tkinter
tk = Tkinter.Tk()
var = Tkinter.StringVar()
print var._name
def cb(name,...
|
by: seanacais |
last post by:
I'm trying to build an unknown number of repeating gui elements
dynamically so I need to store the variables in a list of
dictionaries. I understand that Scale "variable" name needs to be a...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |