Python Forum
Putting frames on separate lines
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Putting frames on separate lines
#1
Hello. I am trying to create an input window that prompts for two files.
I created two frames, frame1 and frame2. I inserted a label and entry widget in each frame.
When I run the program, it puts everything on a single line.
I would like to put the prompts on separate lines.
Below is an excerpt of the code I wrote.
Thanks in advance! Smile


mw = Tk()
# 999x999 is size of window, 999+999 is the location of the window
mw.geometry('800x400+400+200')
mw.title("Test Program")

frame1 = Frame(mw).pack(side=TOP,anchor=W,fill=X,expand=YES)
frame2 = Frame(mw).pack(side=TOP,anchor=W,fill=X,expand=YES)
framebot = Frame(mw).pack(side=BOTTOM,anchor=W,fill=X,expand=YES)



w1 = Label(frame1, text="Input File: ",font=("Times",25)).pack(side=LEFT)
e1 = Entry(frame1,width=25,font=("Times",25))
e1.insert(0, "infile.txt")
e1.pack(side=LEFT)

Button(frame1,text='Search',font=("Times",25),command=get_file1).pack(side=LEFT)


w2 = Label(frame2, text="Output File: ",font=("Times",25)).pack(side=LEFT)
e2 = Entry(frame2,width=25,font=("Times",25))
e2.insert(0, "outfile.txt")
e2.pack(side=LEFT)

Button(frame2,text='Search',font=("Times",25),command=get_file2).pack(side=LEFT)


Button(framebot,text='Go',font=("Times",25),command=show_entry_fields).pack()
Button(framebot,text='Exit',font=("Times",25),command=mw.quit).pack()

mw.mainloop()
Reply
#2
I want each prompt to be on its own line as show in the following image:
https://imgur.com/AkqyZqr

But the above program produces all the prompts on a single line:
https://imgur.com/HzGZdKU
Reply
#3
Below is my full python program in case you cannot figure it out from the program excerpt.
When you run the program, all the frames appear on the same line.
If anybody can figure out why it does this, it would be appreciated.


from tkinter import filedialog
from tkinter import *
import tkinter.font as font
#import tkinter as tk

def show_entry_fields():
	fname1 = e1.get()
	fname2 = e2.get()
	print("Input File: %s\nOutput File: %s" % (fname1, fname2))

	f1 = open(fname1,"r")
	lines = f1.readlines()
	for x in lines:
		print(x)
	f1.close()



def get_file1():
	file1 =  filedialog.askopenfilename(title = "Select file",filetypes = (("all files","*.*"),("jpeg files","*.jpg"),("python files","*.py")))
	e1.delete(0,'end')
	e1.insert(0,file1)

def get_file2():
	file2 =  filedialog.askopenfilename(title = "Select file",filetypes = (("all files","*.*"),("jpeg files","*.jpg"),("python files","*.py")))
	e2.delete(0,'end')
	e2.insert(0,file2)



mw = Tk()
# 999x999 is size of window, 999+999 is the location of the window
mw.geometry('800x400+400+200')
mw.title("Test Program")

frame1 = Frame(mw).pack(side=TOP,anchor=W,fill=X,expand=YES)
frame2 = Frame(mw).pack(side=TOP,anchor=W,fill=X,expand=YES)
framebot = Frame(mw).pack(side=BOTTOM,anchor=W,fill=X,expand=YES)



w1 = Label(frame1, text="Input File: ",font=("Times",25)).pack(side=LEFT)
e1 = Entry(frame1,width=25,font=("Times",25))
e1.insert(0, "infile.txt")
e1.pack(side=LEFT)

Button(frame1,text='Search',font=("Times",25),command=get_file1).pack(side=LEFT)


w2 = Label(frame2, text="Output File: ",font=("Times",25)).pack(side=LEFT)
e2 = Entry(frame2,width=25,font=("Times",25))
e2.insert(0, "outfile.txt")
e2.pack(side=LEFT)

Button(frame2,text='Search',font=("Times",25),command=get_file2).pack(side=LEFT)


Button(framebot,text='Go',font=("Times",25),command=show_entry_fields).pack()
Button(framebot,text='Exit',font=("Times",25),command=mw.quit).pack()

mw.mainloop()
Reply
#4
I found the problem with the program.
The problem is caused by defining the frames and packing them at the same time.
The following code is incorrect:
frame1 = Frame(mw).pack(side=TOP,anchor=W,fill=X,expand=YES)
frame2 = Frame(mw).pack(side=TOP,anchor=W,fill=X,expand=YES)
framebot = Frame(mw).pack(side=BOTTOM,anchor=W,fill=X,expand=YES)
The correct code is as follows:
frame1 = Frame(mw)
frame2 = Frame(mw)
framebot = Frame(mw)
frame1.pack(side=TOP,fill=X)
frame2.pack(side=TOP,fill=X)
framebot.pack(side=BOTTOM,fill=X)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  importing functions from a separate python file in a separate directory Scordomaniac 3 1,361 May-17-2022, 07:49 AM
Last Post: Pedroski55
  List / arrays putting in sentence Kurta 3 2,543 Dec-25-2020, 11:29 AM
Last Post: Larz60+
  Iterate 2 large text files across lines and replace lines in second file medatib531 13 5,768 Aug-10-2020, 11:01 PM
Last Post: medatib531
  Putting a condition Jiwan 3 2,717 Apr-25-2020, 11:28 AM
Last Post: anbu23
  Grabbing comma separed values from SQLite and putting them in a list PythonNPC 8 3,993 Apr-10-2020, 02:39 PM
Last Post: buran
  reading txt file putting in list function Expel 7 3,745 Jul-17-2019, 03:18 PM
Last Post: Expel
  Putting text on images from excel/csv file sam77am 1 2,185 Apr-05-2019, 07:36 AM
Last Post: Larz60+
  Putting an array for each string that is printed to a loop ClaudioSimonetti 1 2,332 Feb-05-2019, 12:52 PM
Last Post: perfringo
  Putting many coordinates number inside codes fyec 1 2,194 Jun-07-2018, 01:09 AM
Last Post: scidam
  How to list objects on separate lines? Intelligent_Agent0 3 4,106 Jan-10-2018, 05:35 AM
Last Post: Intelligent_Agent0

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020