codingdir logo sitemap sitemap |
Home
PHP
C#
C++
ANDROID
JAVA
JAVASCRIPT
PYTHON

Making dynamic list of option menus with invidual variable


By : , Category : python

Here it is a solution using a list comprehension: You just need to create the OptionMenu within an auxiliary function and return the variable you use.

from Tkinter import *

list1 = ['001 aaa', '002 bbb', '003 ccc']
status = ["On", "Off", "Unknown"]
master = Tk()

def create_option(r, x):
    x = x.split(" ", 2)
    variable = StringVar(master)
    Label(master, text=x[0], relief=RIDGE, anchor=W).grid(row=r, column=0, sticky=W+E)
    Label(master, text=x[1], relief=RIDGE, anchor=W).grid(row=r, column=1, sticky=W+E)
    OptionMenu(master, variable, *status).grid(row=r, column=2, sticky=W+E)
    return variable

variables = [create_option(r,x) for r, x in enumerate(list1)]
root.mainloop()
ReLated :

There are probably dozens of ways to accomplish this. Here is one simple way, likely not the most elegant but it works:

@echo off

set _on=0

:top
cls

if %_on%==0 (set _nlb= &set _nrb= &set _flb=[&set _frb=]) else (set _nlb=[&set _nrb=]&set _flb= &set _frb= )

echo The '_on' flag is currently: %_nlb% On %_nrb%  %_flb% Off %_frb%
echo.
echo Press any key to toggle the '_on' flag
pause>nul

if %_on%==0 (set _on=1) else (set _on=0)
goto top

Well I can't explain WHY it's happening. It's certainly peculiar. But I can tell you where the problem is and how to fix it.

For some reason, this is making everything appear backwards:

.title {
  margin-top: -350px;
}

Get rid of that, and you can also get rid of the margin-top setting in .page4 and .span8. Then just pick one of those last two elements and put in a single margin-top which gets you to where you want to be.

Thanks to Jeffrey Scofield and some thinking of my own, we have determined that a great way to do this would be to use List.map and List.filter to separate None from Some and then extract the int from within. The inner function can either be a helper function or an inline function; that is a style preference.

Change your javascript to this:

$('#mylist').on('click', 'li', function () {
    if ($(this).hasClass('selected'))
    {
        $(this).removeClass('selected');
        $('#mylist li').removeClass('not-selected');        
    }
    else
    {
        $('#mylist li').removeClass('selected').addClass('not-selected');
        $(this).removeClass('not-selected').addClass('selected');
    }
});
Comments


Message :
Login to Add Your Comments .
How to disable registered OpenCL platforms on Windows?
Is Observable broken in Angular 2 Beta 3?
Cross-thread operation not valid when using Invoke
How to pass an IEnumerable or queryable list of properties from Controller to View
Finding numbers after a certain keyword using Python
Pocketsphinx recognizes random phrases in a silence
Passing non-thread-safe objects through thread-safe containers
React scroll nav
BizTalk WCF-BasicHttp Adapter does not allow Empty string for Service Certificate Props
Why property ''cause" of Exception is repeating forever?
Privacy Policy 2017 © codingdir.com All Rights Reserved .