By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,731 Members | 1,129 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,731 IT Pros & Developers. It's quick & easy.

can not add buttons to 4 frams using tkinter

P: 3
Can not add button, etc in form. Form has 4 frames and one canvas. Can generate form, but button is not on frame?
---------------------------------------
Expand|Select|Wrap|Line Numbers
  1. from tkinter import *
  2. def Plot():
  3.     root = Tk()
  4.     root.geometry('1340x690+00+00') 
  5.     root.title('Equity bSelection')
  6.     # top border controls
  7.     frame1 = Frame(width=1340, height=200, bg="light  green", colormap="new", borderwidth=0)
  8.     #Button(frame1,text='Plot List', command=sys.exit).pack(side=LEFT)       #command=dispplotlist
  9.     #but1=Button.config(height=3, font=('times',20,'bold')) 
  10.     frame1.pack(side=TOP,padx=0,pady=0)   
  11.  
  12.     # bottom border time scale
  13.     frame2 = Frame(width=1340, height=50, bg="light green", colormap="new", borderwidth=0)
  14.     frame2.pack(side=BOTTOM,padx=0,pady=0)
  15.  
  16.     # left border controls
  17.     frame3 = Frame(width=50, height=450, bg="orange", colormap="new", borderwidth=0)
  18.     frame3.pack(side=LEFT,padx=0,pady=0)
  19.  
  20.     # right border scales for $, and non-$
  21.     frame4 = Frame(width=100, height=450, bg="silver", colormap="new", borderwidth=0)
  22.     frame4.pack(side=RIGHT,padx=0,pady=0)
  23.  
  24.     # charted lines
  25.     canvis1 = Canvas(root, width=1240, height=450, bg='light gray', borderwidth=0)
  26.     canvis1.pack(padx=0,pady=0)
  27. Plot()
  28. mainloop()
---------------------------------------------------
Jan 12 '15 #1
Share this Question
Share on Google+
5 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
Why create separate frames? Shouldn't root be their parent?
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2. def Plot():
  3.     root = Tk()
  4.     root.geometry('1340x690+00+00') 
  5.     root.title('Equity bSelection')
  6.     # top border controls
  7.     frame1 = Frame(root, width=1340, height=200, bg="light green", colormap="new", borderwidth=0)
  8.     but1 = Button(frame1,text='Plot List', command=sys.exit)       #command=dispplotlist
  9.     but1.config(height=3, font=('times',20,'bold'))
  10.     but1.pack(side=LEFT)
  11.     frame1.pack(side=TOP,padx=0,pady=0)   
  12.  
  13.     # bottom border time scale
  14.     frame2 = Frame(root, width=1340, height=50, bg="light green", colormap="new", borderwidth=0)
  15.     frame2.pack(side=BOTTOM,padx=0,pady=0)
  16.  
  17.     # left border controls
  18.     frame3 = Frame(root, width=50, height=450, bg="orange", colormap="new", borderwidth=0)
  19.     frame3.pack(side=LEFT,padx=0,pady=0)
  20.  
  21.     # right border scales for $, and non-$
  22.     frame4 = Frame(root, width=100, height=450, bg="medium blue", colormap="new", borderwidth=0)
  23.     frame4.pack(side=RIGHT,padx=0,pady=0)
  24.  
  25.     # charted lines
  26.     canvis1 = Canvas(root, width=1240, height=450, bg='light gray', borderwidth=0)
  27.     canvis1.pack(padx=0,pady=0)
  28. Plot()
  29. mainloop()
Jan 12 '15 #2

P: 3
For: bvdet

Your posted answer created button on form not on frame!
Expand|Select|Wrap|Line Numbers
  1.     from tkinter import *
  2.     def Plot():
  3.      root = Tk()
  4.      root.geometry('1340x690+00+00')
  5.      root.title('Equity bSelection')
  6.      # top border controls
  7.      frame1 = Frame(root, width=1340, height=50, bg="light green")
  8.  
  9.      but1 = Button(frame1,text='Plot List', command=sys.exit)       #command=dispplotlist
  10.      but1.config(height=3, font=('times',20,'bold'))
  11.      but1.pack(side=LEFT)
  12.      frame1.pack(side=TOP)
  13.  
  14.      # bottom border time scale
  15.      frame2 = Frame(root, width=1340, height=50, bg="light green", colormap="new", borderwidth=0)
  16.      frame2.pack(side=BOTTOM,padx=0,pady=0)
  17.  
  18.      # left border controls
  19.      frame3 = Frame(root, width=50, height=450, bg="orange", colormap="new", borderwidth=0)
  20.      frame3.pack(side=LEFT,padx=0,pady=0)
  21.  
  22.      # right border scales for $, and non-$
  23.      frame4 = Frame(root, width=100, height=450, bg="medium blue", colormap="new", borderwidth=0)
  24.      frame4.pack(side=RIGHT,padx=0,pady=0)
  25.  
  26.      # charted lines
  27.      canvis1 = Canvas(root, width=1240, height=450, bg='light gray', borderwidth=0)
  28.      canvis1.pack(padx=0,pady=0)
  29. Plot()
  30. mainloop()
============================================
Your code work; created button on form and removed frame?
Jan 13 '15 #3

bvdet
Expert Mod 2.5K+
P: 2,851
I don't know what you are trying to do. Do you want a separate top level widget to contain the button?
Jan 13 '15 #4

P: 3
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!
Jan 14 '15 #5

bvdet
Expert Mod 2.5K+
P: 2,851
You could arrange your frames and canvas on one top level window. I don't get it.
Jan 14 '15 #6

Post your reply

Sign in to post your reply or Sign up for a free account.