Hey,
I'm pretty new to programming. Been trying to learn using Python.
The code I'm struggling with is for my GUI.
I'm am having trouble getting this to display the way I want with the
grid manager. Can anybody tell me what I am doing wrong? I hope you
can tell what look I'm trying to achieve from the code as its hard to
explain.
I think my main questions are:
1. How can I get the Window to be sized the way I want it?
2. How can I get the Scrollbars to fill the side of the text box
instead of being small? (like .pack(fill= tk.Y)
######Code#######
#file/path finder
#indentation value 4
import os,glob
import Tkinter as tk
# Class to create the Application and UI
class Theapp:
def __init__(self):
# Create GUI parts. Will allign later with grid
self.top = tk.Tk()
self.mainWindow = tk.Frame(self.top, width=700, height=400)
self.labAll = tk.Label(self.mainWindow, text="All Files/
Folders:")
self.labVi = tk.Label(self.mainWindow, text="Violating Files/
Folders:")
#Create a sub-frame containing textbox and scrollbar for All
files scanned display
self.allTxtf = tk.Frame(self.mainWindow, width=699,
height=164)
self.scrlr1 = tk.Scrollbar(self.allTxtf)
self.txtBoxall = tk.Text(self.allTxtf, wrap=tk.CHAR,
yscrollcommand=self.scrlr1.set)
self.scrlr1.config(command = self.txtBoxall.yview)
#Create another sub-frame containing textbox and scrollbar for
the Violating files display
self.viTxtf = tk.Frame(self.mainWindow, width=699, height=164)
self.scrlr2 = tk.Scrollbar(self.viTxtf)
self. txtBoxvi = tk.Text(self.viTxtf, wrap=tk.CHAR,
yscrollcommand=self.scrlr2.set)
self.scrlr2.config(command = self.txtBoxvi.yview)
#Create another sub-frame to contain the controls
self.ctrlFrame = tk.Frame(self.mainWindow, width=699,
height=72)
self.labDir = tk.Label(self.ctrlFrame, text="Dir:")
self.entDir = tk.Entry(self.ctrlFrame)
self.labChar = tk.Label(self.ctrlFrame, text="Char. Limit:")
self.entChar = tk.Entry(self.ctrlFrame)
self.btFind = tk.Button(self.ctrlFrame, text="Scan", command =
self.fillboxes)
self.btExit = tk.Button(self.ctrlFrame, text="Exit", command =
self.quitEvent)
#Use tkinter's grid geometry manager to allign and display the
GUI
self.mainWindow.grid()
#Frist allign the 3 main frames
self.labAll.grid(row=0)
self.allTxtf.grid(row=1)
self.labVi.grid(row=2)
self.viTxtf.grid(row=3)
self.ctrlFrame.grid(row=4)
#Now allign the content of allTxtf
self.txtBoxall.grid(row=0, column=0)
self.scrlr1.grid(row=0, column=1)
#Now allign the content for viTxtf
self.txtBoxvi.grid(row=0, column=0)
self.scrlr2.grid(row=0, column=1)
#Now allign the content for ctrlFrame
self.labDir.grid(row=0, column=0, sticky=tk.E)
self.entDir.grid(row=0, column=1)
self.labChar.grid(row=0, column=2, sticky=tk.E)
self.entChar.grid(row=0, column=3)
self.btFind.grid(row=0, column=4)
self.btExit.grid(row=0,column=5)
def findallfiles(self, base):
pass
def fillboxes(self):
pass
def quitEvent(self):
raise SystemExit
app = Theapp()
app.mainWindow.mainloop()
######End Code#######
I have only posted the code relevant to the GUI.
TIA
Adam 6 2491
Adam wrote:
<snip>
I think my main questions are:
1. How can I get the Window to be sized the way I want it?
2. How can I get the Scrollbars to fill the side of the text box
instead of being small? (like .pack(fill= tk.Y)
<snip>
>
I have only posted the code relevant to the GUI.
TIA
Adam
To size the window use Tk's geometry method
self.top.geometry("%dx%d%+d%+d" % (800, 600, 0, 0)) # (width,
height, x, y)
For the scrollbar to fill vertically, use the sticky grid option.
self.scrlr1.grid(row=0, column=1, sticky=tk.N + tk.S)
Hope this helps.
Adonis
On Feb 28, 9:13 pm, Adonis Vargas <ado...@REMOVETHISearthlink.net>
wrote:
Adam wrote:
<snip>
I think my main questions are:
1. How can I get the Window to be sized the way I want it?
2. How can I get the Scrollbars to fill the side of the text box
instead of being small? (like .pack(fill= tk.Y)
<snip>
I have only posted the code relevant to the GUI.
TIA
Adam
To size the window use Tk's geometry method
self.top.geometry("%dx%d%+d%+d" % (800, 600, 0, 0)) # (width,
height, x, y)
For the scrollbar to fill vertically, use the sticky grid option.
self.scrlr1.grid(row=0, column=1, sticky=tk.N + tk.S)
Hope this helps.
Adonis
Can't test now as its late in th UK and I'm going to bed. Looks good
though.
So remove the size from the frames etc and use the geometry method
instead? Then use grid to "pack" them for want of a better word?
Adam wrote:
On Feb 28, 9:13 pm, Adonis Vargas <ado...@REMOVETHISearthlink.net>
wrote:
>Adam wrote:
<snip>
>>I think my main questions are: 1. How can I get the Window to be sized the way I want it? 2. How can I get the Scrollbars to fill the side of the text box instead of being small? (like .pack(fill= tk.Y)
<snip>
>>I have only posted the code relevant to the GUI. TIA Adam
To size the window use Tk's geometry method
self.top.geometry("%dx%d%+d%+d" % (800, 600, 0, 0)) # (width, height, x, y)
For the scrollbar to fill vertically, use the sticky grid option.
self.scrlr1.grid(row=0, column=1, sticky=tk.N + tk.S)
Hope this helps.
Adonis
Can't test now as its late in th UK and I'm going to bed. Looks good
though.
So remove the size from the frames etc and use the geometry method
instead? Then use grid to "pack" them for want of a better word?
No, the geometry method is used to set the size of your main application
window. This is what I understood from your first question, and please
correct me if I am wrong. The grid method (or the pack method) are used
to layout the widgets.
In other words, after line 8 of the code you provided you would add this
line:
self.top.geometry("%dx%d%+d%+d" % (800, 600, 0, 0))
Hope this helps.
Adonis
Ok the window has resized but the elements inside are still like they
were, so they are going off the edge on the window. How can I get
these to resize? I have put sizes on the frames they are in. Sorry to
keep asking but I'm flying blind here, I have checked the python site
and the intro to tkinter which are both usually good for this kinda
thing.
#####CODE#####
#file/path finder
#indentation value 4
import os,glob
import Tkinter as tk
# Class to create the Application and UI
class Theapp:
def __init__(self):
# Create GUI parts. Will allign later with grid
self.top = tk.Tk()
self.top.geometry("%dx%d%+d%+d" % (700, 400, 0, 0)) #
(width,height, x, y)
self.mainWindow = tk.Frame(self.top)#width=700, height=400)
self.labAll = tk.Label(self.mainWindow, text="All Files/
Folders:")
self.labVi = tk.Label(self.mainWindow, text="Violating Files/
Folders:")
#Create a sub-frame containing textbox and scrollbar for All
files scanned display
self.allTxtf = tk.Frame(self.mainWindow, width=690,
height=164)
self.scrlr1 = tk.Scrollbar(self.allTxtf)
self.txtBoxall = tk.Text(self.allTxtf, wrap=tk.CHAR,
yscrollcommand=self.scrlr1.set)
self.scrlr1.config(command = self.txtBoxall.yview)
#Create another sub-frame containing textbox and scrollbar for
the Violating files display
self.viTxtf = tk.Frame(self.mainWindow, width=690, height=164)
self.scrlr2 = tk.Scrollbar(self.viTxtf)
self. txtBoxvi = tk.Text(self.viTxtf, wrap=tk.CHAR,
yscrollcommand=self.scrlr2.set)
self.scrlr2.config(command = self.txtBoxvi.yview)
#Create another sub-frame to contain the controls
self.ctrlFrame = tk.Frame(self.mainWindow, width=690,
height=72)
self.labDir = tk.Label(self.ctrlFrame, text="Dir:")
self.entDir = tk.Entry(self.ctrlFrame)
self.labChar = tk.Label(self.ctrlFrame, text="Char. Limit:")
self.entChar = tk.Entry(self.ctrlFrame, textvariable="254")
self.btFind = tk.Button(self.ctrlFrame, text="Scan", command =
self.fillboxes)
self.btExit = tk.Button(self.ctrlFrame, text="Exit", command =
self.quitEvent)
#Use tkinter's grid geometry manager to allign and display the
GUI
self.mainWindow.grid()
#Frist allign the 3 main frames
self.labAll.grid(row=0)
self.allTxtf.grid(row=1)
self.labVi.grid(row=2)
self.viTxtf.grid(row=3)
self.ctrlFrame.grid(row=4)
#Now allign the content of allTxtf
self.txtBoxall.grid(row=0, column=0)
self.scrlr1.grid(row=0, column=1, sticky=tk.N + tk.S)
#Now allign the content for viTxtf
self.txtBoxvi.grid(row=0, column=0)
self.scrlr2.grid(row=0, column=1, sticky=tk.N + tk.S)
#Now allign the content for ctrlFrame
self.labDir.grid(row=0, column=0, sticky=tk.E)
self.entDir.grid(row=0, column=1)
self.labChar.grid(row=0, column=2, sticky=tk.E)
self.entChar.grid(row=0, column=3)
self.btFind.grid(row=0, column=4)
self.btExit.grid(row=0,column=5)
def findallfiles(self, base):
Pass
def fillboxes(self):
Pass
def quitEvent(self):
raise SystemExit
app = Theapp()
app.mainWindow.mainloop()
#####END#####
Regards,
Adam
On Thu, 01 Mar 2007 21:01:40 +0100, Adam <ad**********@googlemail.com
wrote:
Ok the window has resized but the elements inside are still like they
were, so they are going off the edge on the window. How can I get
these to resize? I have put sizes on the frames they are in. Sorry to
keep asking but I'm flying blind here, I have checked the python site
and the intro to tkinter which are both usually good for this kinda
thing.
[snip code]
I've not tried your code, but it seems to be missing some grid
configuration. Basically, you need to tell all containers what row(s) or
column(s) will grow or shrink when the container itself grows or shrink.
This is done by calling the grid_rowconfigure and grid_columnconfigure
methods on the container, passing the weight option:
container.grid_rowconfigure(0, weight=1)
means that when the container size changes, all rows will (try to) stay
the same, except row number 0 which will adapt its size to the new
container size. (This is actually a bit more complicated than that, but it
should suit your needs for the moment).
Since the default weight for all rows and columns is 0, meaning "don't
change your size", the behavior you see is quite normal.
A little tip: things are usually a bit more complicated when you have
several levels of frames within each other. Specifying a "flashy"
background color for frames can help you to figure out which one does
change its size as you want. Use bg='red' or bg='green' in your Frame
creations to make obvious where they are; you'll see far clearly what
happens when you resize your window.
A few short notes:
- You don't need at all to put all your widgets in attributes. Unless
you'll have to access the widget itself later (e.g to change it state or
color, or whatever), putting it in a local variable is fine.
- In your code, it appears to me that self.mainWindow is not needed. The
Tk instance (self.top) *is* the top-level window and is a valid container
for whatever widgets you need. Having a Frame inside it will only cause
layout problems. I'd do:
self.mainWindow = tk.Tk()
self.mainWindow.geometry('700x400+0+0')
self.labAll = tk.Label(self.mainWindow, text="All Files/Folders:")
...
HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
Thanks for the reply, will work with this tomorrow.
Adam This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dennis Sylvester |
last post by:
Interested in any opinions, studies, etc., concerning the GUI tool(s) to use
for Python. Specifically, which would you recommend (and why) for building
GUI apps in Python:
TKinter
BOA
PyQT
...
|
by: Rob Andrews |
last post by:
I'm on a Red Hat 9 system, which has Python 2.2.2 installed, and I installed
2.3 separately into /home/rob/Python-2.3/ (creating the symbolic link
"py23" to point to my 2.3 installation). Now I'm...
|
by: Abstractius |
last post by:
Hello,
I was able to unearth some ancient documentation suggesting Modules/Setup
has to be edited by hand (after ./configure) to compile tkinter. The short
info at...
|
by: Rob Dijkshoorn |
last post by:
Hi All,
I have some problems building the python modules, most notably Tkinter, on
AIX 5.1. Can anyone be of any assistance?
Thanks,
Rob
This is what the compiler spits out:
|
by: Andrew |
last post by:
Hi I was wondering if there is anyway in Tkinter to create GUIs using
Graphics, like windows media player or other tools like that
basically so the interface wouldn't be your standard interface
...
|
by: Harlin Seritt |
last post by:
There are certain options for Tkinter widgets that have default values
that I don't much care for (borderwidth, font come to mind) and
continuously change when I'm building interfaces. With a bit...
|
by: Andrew Trevorrow |
last post by:
Our app uses embedded Python to allow users to run arbitrary scripts.
Scripts that import Tkinter run fine on Windows, but on Mac OS X there
is a serious problem. After a script does "root = Tk()"...
|
by: frikk |
last post by:
Hey everyone. I have been working with python for a couple years now,
but just recently built my first program with a GUI. I decided to
start with Tkinter since it is included with the base...
|
by: Miki |
last post by:
Hello,
Tk.lift doesn't seem to work on OSX (Python 2.5.1).
The below starts OK, but the window is the behind all other windows.
from Tkinter import *
root = Tk()
Button(root, text="OK",...
|
by: njwilson23 |
last post by:
I'm having trouble with tkinter on a new installation of Python (2.6),
built with the framework option from source that was downloaded from
python.org. I'm running OS 10.4 on a PowerPC G4.
The...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |