[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Cascade menus and functions in Python

Posted on 2009-04-02
3
Medium Priority
?
590 Views
Last Modified: 2012-06-22
The first code shows the table I am trying to make and the 2nd code shows my attempt in making a cascade drop down list of the teams I want to associate in the Names column of code 1. Basically what I want to do is, prompt the user with 10 teams from which the user will select a team. Once the user selects a team, he or she can then carry on to the next column where he or she will get a drop down menu, similar to code 2 but in numbers, and will choose wins ranging from 1-10, since im only going to be counting 10 games. and then the user goes onto the next column and does the same for draw, loss, and goals. For the first 4, I want cascade menus but for goals, I want an entry box where the user can input the number. After that, I want a submit button that will save all the entries in "testing.txt" I have spent a lot of hours trying to find solutions on the internet but I have failed to do so, and since I am new to python, I do not have much knowledge of it other than what I have learned here and there. Thanks a lot for your help in advance.


***EDIT***
I figured out how to submit the data input by the user. Now the only thing I need is how to make a drop down menu to be able to select a team and a number of wins/loss/etc ranging 1-10 -- Please help :-(
from Tkinter import *
import analyse
 
 
 
def run_analyse(db):
    window = Tk()
   
    frame = Frame(window)
    frame.pack()
    
    q1_prompt = Label(frame, text="Team 1:")
    q1_prompt.grid(row=1, column=0)
    q1_prompt = Label(frame, text="Names")
    q1_prompt.grid(row=0, column=0)
 
 
    q1_prompt = Label(frame, text="Wins")
    q1_prompt.grid(row=0, column=1)
    
    
    q2_prompt = Label(frame, text="Team 2:")
    q2_prompt.grid(row=2, column=0)
    q2_prompt = Label(frame, text="Draws")
    q2_prompt.grid(row=0, column=2)
    
   
    q3_prompt = Label(frame, text="Team 3:")
    q3_prompt.grid(row=3, column=0)
    q3_prompt = Label(frame, text="Losses")
    q3_prompt.grid(row=0, column=3)
    
    
    q4_prompt = Label(frame, text="Team 4:")
    q4_prompt.grid(row=4, column=0)
    q4_prompt = Label(frame, text="Goals")
    q4_prompt.grid(row=0, column=4)
    q4_data = Entry(frame)
    q4_data.grid(row=1, column=4)
    q4_data = Entry(frame)
    q4_data.grid(row=2, column=4)
    q4_data = Entry(frame)
    q4_data.grid(row=3, column=4)
    q4_data = Entry(frame)
    q4_data.grid(row=4, column=4)
    q4_data = Entry(frame)
    q4_data.grid(row=5, column=4)
    q4_data = Entry(frame)
    q4_data.grid(row=6, column=4)
    q4_data = Entry(frame)
    q4_data.grid(row=7, column=4)
    q4_data = Entry(frame)
    q4_data.grid(row=8, column=4)
    q4_data = Entry(frame)
    q4_data.grid(row=9, column=4)
    q4_data = Entry(frame)
    q4_data.grid(row=10, column=4)
        
    q5_prompt = Label(frame, text="Team 5:")
    q5_prompt.grid(row=5, column=0)
    
    
    q6_prompt = Label(frame, text="Team 6:")
    q6_prompt.grid(row=6, column=0)
   
   
    q7_prompt = Label(frame, text="Team 7:")
    q7_prompt.grid(row=7, column=0)
    
    
    q8_prompt = Label(frame, text="Team 8:")
    q8_prompt.grid(row=8, column=0)
    
       
    q9_prompt = Label(frame, text="Team 9:")
    q9_prompt.grid(row=9, column=0)
   
    
    q10_prompt = Label(frame, text="Team 10:")
    q10_prompt.grid(row=10, column=0)
    
    
    window.mainloop()
    
 
    
if __name__=="__main__":
    run_analyse('test.txt')
    
////
 
from Tkinter import *
 
class TestMenu:
    def __init__(self, master):
        self.master = master
        self.menubar = Menu(self.master)
 
        self.casmenu = Menu(self.menubar)
        self.casmenu.choices = Menu(self.casmenu)
        self.casmenu.choices.wierdones = Menu(self.casmenu.choices)
        self.casmenu.choices.wierdones.add_command(label='Man Utd')
        self.casmenu.choices.wierdones.add_command(label='Liverpool')
        self.casmenu.choices.wierdones.add_command(label='Chelsea')
        self.casmenu.choices.wierdones.add_command(label='Arsenal')
        self.casmenu.choices.wierdones.add_command(label='Aston Villa')
        self.casmenu.choices.wierdones.add_command(label='Everton')
        self.casmenu.choices.wierdones.add_command(label='Wigan Athletic')
        self.casmenu.choices.wierdones.add_command(label='West Ham Utd')
        self.casmenu.choices.wierdones.add_command(label='Fulham')
        self.casmenu.choices.wierdones.add_command(label='Man City')
    
 
        
        self.casmenu.choices.add_command(label='Man. Utd.')
        self.casmenu.choices.add_command(label='Liverpool')
        self.casmenu.choices.add_command(label='Chelsea')
        self.casmenu.choices.add_command(label='Arsenal')
        self.casmenu.choices.add_command(label='Aston Villa')
        self.casmenu.choices.add_command(label='Everton')
        self.casmenu.choices.add_command(label='Wigan Athletic')
        self.casmenu.choices.add_command(label='West Ham Utd')
        self.casmenu.choices.add_command(label='Fulham')
        self.casmenu.choices.add_command(label='Man City')
    
 
        self.casmenu.add_cascade(label='Teams',
                                      menu=self.casmenu.choices)
 
        self.unused = Menu(self.menubar)
        
        self.menubar.add_cascade(label="Teams", menu=self.casmenu)
 
        self.top = Toplevel(menu=self.menubar, width=100, relief=RAISED, borderwidth=10)
 
def main():
    root = Tk()
    root.withdraw()
    app = TestMenu(root)
    root.mainloop()
 
if __name__ == '__main__':
    main()

Open in new window

0
Comment
Question by:Student_101
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Author Comment

by:Student_101
ID: 24055988
***EDIT***
I forgot to mention that I want this in 1 file and not 2.. sorry for the confusion
0
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 500 total points
ID: 24065419
You must associate the dropdown menu items with a command, for instance like this:

        self.casmenu.choices.add_command(label='Man. Utd.',command=self.set_name('Man. Utd.'))

...and then have a method in the TestMenu class like below, assigning the team name to the class property "team_name":
    def set_name(self,name):
        def do_set_name(name=name,s=self):
            s.team_name = name
        return do_set_name

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Plenty of writing has gone on the web trying to compare Python with other competitive programming languages and vice versa. However, not much has been put into a wholistic perspective. This article should help you decide whether to adopt Python as a…
Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question