Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7685047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:09:59+00:00 2026-05-31T19:09:59+00:00

I’m making a baseball program based on the strategy games produced by Avalon Hills

  • 0

I’m making a baseball program based on the strategy games produced by Avalon Hills from the 70s & 80s, and the last part is a gui. I’ve made all the code to run the game command line, and I’ve got the code to select lineups with a gui. I envision a 3by1 grid with a scoreboard on the first row, a text box displaying the result, out, home run, double play, etc., and the last row is divided between the pitcher and batter cards on the left side, and a frame of buttons. The frame will flip between an offence and defence frame. So first the defence frame comes up with options like pitching change, change position, and play ball. Play ball changes the frame to the offence options, which will be pinch hit, pinch run, steal, and so on. But how can I put the buttons inside a frame, then combine the player cards and buttons in another frame, and then add that to the main frame?

The DFrame & OFrame classes are inner classes (hence the “elf”, not “self”). I’ve got the dynamic switching between the 2 Frames. My problem is breaking the DFrame main loop, it only plays the top of the first, and the self.roadOuts never increments. Here’s what I’ve got:

while self.innings < 8.5 or self.homeScore == self.roadScore:
    self.roadOuts = 0
    while self.roadOuts < 3:
        self.dFrame.mainloop()

class DFrame(Frame):
    def __init__(elf, parent):
        Frame.__init__(elf)
        elf._playButton = Button(elf, text = 'Play Ball',
                                command = parent.oMenu)
        elf._playButton.grid(row = 0, column = 0)
        elf._pitchingButton = Button(elf, text = 'Pitching Change',
                                command = parent.pitchingChange)
        elf._pitchingButton.grid(row = 1, column = 0)
        elf._positionButton = Button(elf, text = 'Defensive Substitution',
                                command = parent.positionChange)
        elf._positionButton.grid(row = 0, column = 1)
        elf._alignButton = Button(elf, text = 'Change Positions',
                                command = parent.positionSwap)
        elf._alignButton.grid(row = 1, column = 1)
        elf._doubleButton = Button(elf, text = 'Double Switch',
                                command = parent.doubleSwitch)
        elf._doubleButton.grid(row = 2, column = 0)
        elf._walkButton = Button(elf, text = 'Intentional Walk',
                                command = parent.intentionalWalk)
        elf._walkButton.grid(row = 2, column = 1)
        elf._depthButton = Button(elf, text = 'Change Infield Depth',
                                command = parent.infieldDepth)
        elf._depthButton.grid(row = 3, column = 0)

class OFrame(Frame):
    def __init__(elf, parent):
        Frame.__init__(elf)
        elf._playButton = Button(elf, text = 'Play Ball',
                                command = parent.atBat)
        elf._playButton.grid(row = 0, column = 0)
        elf._pinchHitButton = Button(elf, text = 'Pinch Hit',
                                command = parent.pinchHit)
        elf._pinchHitButton.grid(row = 1, column = 0)
        elf._prfButton = Button(elf, text = 'Pinch Run First',
                                command = parent.pinchRunFirst)
        elf._prfButton.grid(row = 0, column = 1)
        elf._prsButton = Button(elf, text = 'Pinch Run Second',
                                command = parent.pinchRunSecond)
        elf._prsButton.grid(row = 1, column = 1)
        elf._prtButton = Button(elf, text = 'Pinch Run Third',
                                command = parent.pinchRunThird)
        elf._prtButton.grid(row = 2, column = 1)
        elf._stealButton = Button(elf, text = 'Steal',
                                command = parent.steal)
        elf._stealButton.grid(row = 2, column = 0)
        elf._bunt4HitButton = Button(elf, text = 'Bunt for a hit',
                                command = parent.bunt4AHit)
        elf._bunt4HitButton.grid(row = 3, column = 0)
        elf._hitNRunButton = Button(elf, text = 'Hit And Run',
                                command = parent.hitAndRun)
        elf._hitNRunButton.grid(row = 4, column = 0)
        elf._sacButton = Button(elf, text = 'Sacrifice',
                                command = parent.sacrifice)
        elf._sacButton.grid(row = 4, column = 1)
        elf._squeezeButton = Button(elf, text = 'Squeeze',
                                command = parent.squeeze)
        elf._squeezeButton.grid(row = 3, column = 1)

the next method is called when the DFrame “play ball” button is clicked, and it makes the OFrame.

def oMenu(self):
    self.dFrame.grid_forget()
    self.dFrame.destroy()
    self.oFrame = self.OFrame(self)
    self.oFrame.grid(row = 1, column = 1)
    self.oFrame.mainloop()

and at the end of an at bat, I have:

self.oFrame.grid_forget()
self.oFrame.destroy()
self.dFrame = self.DFrame(self)
self.dFrame.grid(row = 1, column = 1)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:10:00+00:00Added an answer on May 31, 2026 at 7:10 pm

    I’m not sure I understand your question. It seems like you know how to put one frame in another (It is really not much different than adding a Button to a frame — or any other widget). I think what you’re asking is how to dynamically switch which frame is being displayed at any given time.

    You probably want the grid_forget method. using the play_ball button should cause the defense_frame to call it’s grid_forget method, while re-gridding the the offense_frame. Of course, this would be pack_forget if you’re using the pack geometry manager.

    EDIT

    Added a very rudimentary working example of the grid layout you described. It can probably be done a lot better, but this should get you started. (Particularly the switchOffenseDefense function and the switch_button button).

    import Tkinter as tk
    
    base=tk.Tk()  #this is the main frame
    root=tk.Frame(base)  #Really this is not necessary -- the other widgets could be attached to "base", but I've added it to demonstrate putting a frame in a frame.
    root.grid(row=0,column=0)
    scoreboard=tk.Frame(root)
    scoreboard.grid(row=0,column=0,columnspan=2)
    
    ###
    #Code to add stuff to scoreboard ...
    # e.g. 
    ###
    scorestuff=tk.Label(scoreboard,text="Here is the scoreboard")
    scorestuff.grid(row=0,column=0)
    #End scoreboard
    
    #Start cards.
    cards=tk.Frame(root)
    cards.grid(row=1,column=0)
    ###
    # Code to add pitcher and batter cards
    ###
    clabel=tk.Label(cards,text="Stuff to add cards here")
    clabel.grid(row=0,column=0)
    #end cards
    
    #Offense/Defense frames....
    offense=tk.Frame(root)
    offense.grid(row=1,column=1)
    offense.isgridded=True #Dynamically add "isgridded" attribute.
    offense_label=tk.Label(offense,text="Offense is coolest")
    offense_label.grid(row=0,column=0)
    
    defense=tk.Frame(root)
    defense.isgridded=False
    defense_label=tk.Label(defense,text="Defense is coolest")
    defense_label.grid(row=0,column=0)
    
    def switchOffenseDefense():
        print "Called"
        if(offense.isgridded):
            offense.isgridded=False
            offense.grid_forget()
            defense.isgridded=True
            defense.grid(row=1,column=1)
         else:
            defense.isgridded=False
            defense.grid_forget()
            offense.isgridded=True
            offense.grid(row=1,column=1)
    
    
    switch_button=tk.Button(root,text="Switch",command=switchOffenseDefense)
    switch_button.grid(row=2,column=1)
    
    root.mainloop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I'm making a simple page using Google Maps API 3. My first. One marker

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.