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_opti on = OptionMenu(self , default_option, *OPTIONS)
self.month_opti on.grid(row = 5, column = 2, sticky = W) 2 1576
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_opti on = OptionMenu(self , default_option, *OPTIONS)
self.month_opti on.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").g rid(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(r oot, default_option, *OPTIONS.keys() )
month_option.gr id(row=1, column=2, sticky=Tk.W)
Tk.Button(root, command=state, text='state').g rid(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 correspondin g 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***********@a cm.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 = IntVar()
for part, list in info.masterList.items():
|
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 script as a
bunch of asynchronously called subroutines).
I decided to use Tkinter's wait_variable. I built a "script runner"
object that has suitable wait methods. Internally each of these methods
registers a callback that sets a variable when...
|
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 still exists and has a tkinter
name, so testing for None is not feasible:
>>> import Tkinter
>>> fin = None
>>> fin1 = Tkinter.Toplevel()
|
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 code structure is:
def createWidgets(self):
...
var = StringVar()
Entry(master,textvariable=var)
...
|
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 that I would
like to use among all of them, namely the TKinter background. It's
build using tkinter, so, to do anything useful requires having the
master=Tk() variable portable in every interface. I can't just pass
this variable, the real way to...
| |
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 I am hoping someone knows what I am
doing wrong:
1) Pressing the Settings.. Button multiple times, brings up many instances
of the Settings Panel. I just want it to bring up one. Is there an easy
way to do 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 World')
|
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, index, mode):
|
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
StringVar but I cannot figure out how to initialize the dictionary.
I've tried the following code
ps = PowerSupply() # Instantiate a Power Supply VM Object
numOPs = ps.getOnum() # Find the number of outputs
OPValues = # Global list to...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |