can not add buttons to 4 frams using tkinter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jim newbe
    New Member
    • Jan 2015
    • 3

    can not add buttons to 4 frams using tkinter

    Can not add button, etc in form. Form has 4 frames and one canvas. Can generate form, but button is not on frame?
    ---------------------------------------
    Code:
    from tkinter import *
    def Plot():
        root = Tk()
        root.geometry('1340x690+00+00') 
        root.title('Equity bSelection')
        # top border controls
        frame1 = Frame(width=1340, height=200, bg="light  green", colormap="new", borderwidth=0)
        #Button(frame1,text='Plot List', command=sys.exit).pack(side=LEFT)       #command=dispplotlist
        #but1=Button.config(height=3, font=('times',20,'bold')) 
        frame1.pack(side=TOP,padx=0,pady=0)   
       
        # bottom border time scale
        frame2 = Frame(width=1340, height=50, bg="light green", colormap="new", borderwidth=0)
        frame2.pack(side=BOTTOM,padx=0,pady=0)
       
        # left border controls
        frame3 = Frame(width=50, height=450, bg="orange", colormap="new", borderwidth=0)
        frame3.pack(side=LEFT,padx=0,pady=0)
      
        # right border scales for $, and non-$
        frame4 = Frame(width=100, height=450, bg="silver", colormap="new", borderwidth=0)
        frame4.pack(side=RIGHT,padx=0,pady=0)
       
        # charted lines
        canvis1 = Canvas(root, width=1240, height=450, bg='light gray', borderwidth=0)
        canvis1.pack(padx=0,pady=0)
    Plot()
    mainloop()
    ---------------------------------------------------
    Last edited by Rabbit; Jan 12 '15, 04:13 AM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Why create separate frames? Shouldn't root be their parent?
    Code:
    from Tkinter import *
    def Plot():
        root = Tk()
        root.geometry('1340x690+00+00') 
        root.title('Equity bSelection')
        # top border controls
        frame1 = Frame(root, width=1340, height=200, bg="light green", colormap="new", borderwidth=0)
        but1 = Button(frame1,text='Plot List', command=sys.exit)       #command=dispplotlist
        but1.config(height=3, font=('times',20,'bold'))
        but1.pack(side=LEFT)
        frame1.pack(side=TOP,padx=0,pady=0)   
     
        # bottom border time scale
        frame2 = Frame(root, width=1340, height=50, bg="light green", colormap="new", borderwidth=0)
        frame2.pack(side=BOTTOM,padx=0,pady=0)
     
        # left border controls
        frame3 = Frame(root, width=50, height=450, bg="orange", colormap="new", borderwidth=0)
        frame3.pack(side=LEFT,padx=0,pady=0)
     
        # right border scales for $, and non-$
        frame4 = Frame(root, width=100, height=450, bg="medium blue", colormap="new", borderwidth=0)
        frame4.pack(side=RIGHT,padx=0,pady=0)
     
        # charted lines
        canvis1 = Canvas(root, width=1240, height=450, bg='light gray', borderwidth=0)
        canvis1.pack(padx=0,pady=0)
    Plot()
    mainloop()

    Comment

    • jim newbe
      New Member
      • Jan 2015
      • 3

      #3
      For: bvdet

      Your posted answer created button on form not on frame!
      Code:
          from tkinter import *
          def Plot():
           root = Tk()
           root.geometry('1340x690+00+00')
           root.title('Equity bSelection')
           # top border controls
           frame1 = Frame(root, width=1340, height=50, bg="light green")
                
           but1 = Button(frame1,text='Plot List', command=sys.exit)       #command=dispplotlist
           but1.config(height=3, font=('times',20,'bold'))
           but1.pack(side=LEFT)
           frame1.pack(side=TOP)
      
           # bottom border time scale
           frame2 = Frame(root, width=1340, height=50, bg="light green", colormap="new", borderwidth=0)
           frame2.pack(side=BOTTOM,padx=0,pady=0)
      
           # left border controls
           frame3 = Frame(root, width=50, height=450, bg="orange", colormap="new", borderwidth=0)
           frame3.pack(side=LEFT,padx=0,pady=0)
      
           # right border scales for $, and non-$
           frame4 = Frame(root, width=100, height=450, bg="medium blue", colormap="new", borderwidth=0)
           frame4.pack(side=RIGHT,padx=0,pady=0)
      
           # charted lines
           canvis1 = Canvas(root, width=1240, height=450, bg='light gray', borderwidth=0)
           canvis1.pack(padx=0,pady=0)
      Plot()
      mainloop()
      =============== =============== ==============
      Your code work; created button on form and removed frame?
      Last edited by bvdet; Jan 13 '15, 07:55 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #4
        I don't know what you are trying to do. Do you want a separate top level widget to contain the button?

        Comment

        • jim newbe
          New Member
          • Jan 2015
          • 3

          #5
          There is 4 frames top, bottom, left, right, and canvas in center! Top and left frame will contain buttons, select lists etc. to control plot on canvas. Right frame will contain printed scales for $ amount and other units of measure.
          Bottom frame will contain time scales, day, week etc.
          Canvas well contain plot of equities and stock indicators.
          The reason I want separate frames is to control vertical, and horizontal placement of controls with pack on each frame.
          there well be no controls on canvas; only drawing of lines with colors and other attributes. I need 4 frames to control packing for each.

          In my code the button seems to be on form and not on frame1; the green color is missing!

          Comment

          • bvdet
            Recognized Expert Specialist
            • Oct 2006
            • 2851

            #6
            You could arrange your frames and canvas on one top level window. I don't get it.

            Comment

            Working...