473,654 Members | 3,114 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wxpython wxgrid question

Hi,

I am looking for example code that consists of just a frame and a
grid(10x2). The grid must fill the its parent even if the frame is
resized.

Thanks in advance,

Roger

Jun 3 '06 #1
6 2752
In article <11************ **********@u72g 2000cwu.googleg roups.com>,
<rb*****@hotmai l.com> wrote:
Hi,

I am looking for example code that consists of just a frame and a
grid(10x2). The grid must fill the its parent even if the frame is
resized.


This simple program makes a two element window, the lower half of
which is a gridded set of labels which resize with the window. The
important part is the columnconfigure () and rowconfigure() method
calls on the container widget for the grid.
See
<URL:http://infohost.nmt.ed u/tcc/help/pubs/tkinter/grid-config.html>
http://infohost.nmt.edu/tcc/help/pub...id-config.html

#!/usr/local/bin/python

from Tkinter import *

root = Tk()
# create a frame (unused, but shared with gridded frame)
f = Frame(height = 100)
f.pack(expand = YES, fill = BOTH)

# create a frame for a gridded display
gf = Frame()
gf.pack(expand = YES, fill = BOTH)

# create a 3 x 4 array of labels, each with a different background
# Make each row and column have equal weights, so they'll
# grow and shrink together
for row in range(3):
gf.rowconfigure (row, weight = 1)
for col in range(4):
gf.columnconfig ure(col, weight = 1)
Label(gf, text = "Row: %d\nCol: %d" % (row, col),
bg = "#%02x%02x% 02x" % ((row * 4 + col) * 16,
(row * 4 + col) * 16,
(row * 4 + col) * 16),
fg = "#ffffff"
).grid(row = row, column = col, sticky = NSEW)

root.mainloop()

--
Jim Segrave (je*@jes-2.demon.nl)

Jun 3 '06 #2
rb*****@hotmail .com wrote:

I am looking for example code that consists of just a frame and a
grid(10x2). The grid must fill the its parent even if the frame is
resized.


Have you gone through the wxPython demo application? It contains examples
of every standard control and almost every behavior you might want.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jun 3 '06 #3

Tim Roberts wrote:
rb*****@hotmail .com wrote:

I am looking for example code that consists of just a frame and a
grid(10x2). The grid must fill the its parent even if the frame is
resized.


Have you gone through the wxPython demo application? It contains examples
of every standard control and almost every behavior you might want.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.


Yes, and i have even checked out "wxpython in action". All of the
examples tend to leave white space on the right of the frame. I tried
basic a example with sizers and it didnt work. That why I was
wondering if someone had got it to work.
Roger

Jun 4 '06 #4
rb*****@hotmail .com a écrit :
Tim Roberts wrote:
rb*****@hotmail .com wrote:
I am looking for example code that consists of just a frame and a
grid(10x2). The grid must fill the its parent even if the frame is
resized.

Have you gone through the wxPython demo application? It contains examples
of every standard control and almost every behavior you might want.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.


Yes, and i have even checked out "wxpython in action". All of the
examples tend to leave white space on the right of the frame. I tried
basic a example with sizers and it didnt work. That why I was
wondering if someone had got it to work.
Roger

Hi Roger,
A key point is that the Grid manages itself its available space
according to the size it can have.
If you just tried to create a simple grid within a simple frame, you
probably got a grid filling all the frame space, and it's what you want.
Why that ?
If you do it (for instance with the script below), and you try to
manually reduce/increase the size of the window, you should see
scrollbars at the edge of the window ; these scrollbars come from the
grid, because they take in account the labels row and col (wxGrid comes
from wxScrolledWindo w). You can see that no more space is available
beyond the scrollbar, so the grid takes the whole space.
And why the white space on the right ? This space is not on the right of
the grid, but on the right of the last col. We could think it's like
that because it's not possible to compute an appropriate col size for
the grid cols, but it's not displayed exactly the same in linux and in
windows. In one case it's over the last col (not enough space) and in
the other case it's beyond (too much space). I think that as the program
must work on all the environments, the interface must stay enough
global, and sometimes the display is not perfectly done.
The advantage is that if we let wx decide, we won't have to think how to
set the widgets.
Regards,
jm

#----------------------------------------------------------------------
import wx,wx.grid
#----------------------------------------------------------------------
class MainWindow(wx.F rame):
def __init__(self,p arent,id,title) :
wx.Frame.__init __(self,parent, wx.ID_ANY,title )
#--
self.grid= wx.grid.Grid(id =wx.ID_ANY,pare nt=self)
self.grid.Creat eGrid(numRows=1 0,numCols=2)
self.grid.Fit()
self.Fit()
#--
self.Show(1)
#----------------------------------------------------------------------
app = wx.PySimpleApp( )
frame=MainWindo w(None,-1,'Grid sizer')
app.MainLoop()
del app
#----------------------------------------------------------------------
Jun 7 '06 #5

jean-michel bain-cornu wrote:
rb*****@hotmail .com a écrit :
Tim Roberts wrote:
rb*****@hotmail .com wrote:
I am looking for example code that consists of just a frame and a
grid(10x2). The grid must fill the its parent even if the frame is
resized.
Have you gone through the wxPython demo application? It contains examples
of every standard control and almost every behavior you might want.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.


Yes, and i have even checked out "wxpython in action". All of the
examples tend to leave white space on the right of the frame. I tried
basic a example with sizers and it didnt work. That why I was
wondering if someone had got it to work.
Roger

Hi Roger,
A key point is that the Grid manages itself its available space
according to the size it can have.
If you just tried to create a simple grid within a simple frame, you
probably got a grid filling all the frame space, and it's what you want.
Why that ?
If you do it (for instance with the script below), and you try to
manually reduce/increase the size of the window, you should see
scrollbars at the edge of the window ; these scrollbars come from the
grid, because they take in account the labels row and col (wxGrid comes
from wxScrolledWindo w). You can see that no more space is available
beyond the scrollbar, so the grid takes the whole space.
And why the white space on the right ? This space is not on the right of
the grid, but on the right of the last col. We could think it's like
that because it's not possible to compute an appropriate col size for
the grid cols, but it's not displayed exactly the same in linux and in
windows. In one case it's over the last col (not enough space) and in
the other case it's beyond (too much space). I think that as the program
must work on all the environments, the interface must stay enough
global, and sometimes the display is not perfectly done.
The advantage is that if we let wx decide, we won't have to think how to
set the widgets.
Regards,
jm

#----------------------------------------------------------------------
import wx,wx.grid
#----------------------------------------------------------------------
class MainWindow(wx.F rame):
def __init__(self,p arent,id,title) :
wx.Frame.__init __(self,parent, wx.ID_ANY,title )
#--
self.grid= wx.grid.Grid(id =wx.ID_ANY,pare nt=self)
self.grid.Creat eGrid(numRows=1 0,numCols=2)
self.grid.Fit()
self.Fit()
#--
self.Show(1)
#----------------------------------------------------------------------
app = wx.PySimpleApp( )
frame=MainWindo w(None,-1,'Grid sizer')
app.MainLoop()
del app
#----------------------------------------------------------------------


Thanks Tim,

I knew it was something like that, but I had to ask the question. I
was hoping that there was a way around the problem.

Roger

Jun 9 '06 #6

jean-michel bain-cornu wrote:
rb*****@hotmail .com a écrit :
Tim Roberts wrote:
rb*****@hotmail .com wrote:
I am looking for example code that consists of just a frame and a
grid(10x2). The grid must fill the its parent even if the frame is
resized.
Have you gone through the wxPython demo application? It contains examples
of every standard control and almost every behavior you might want.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.


Yes, and i have even checked out "wxpython in action". All of the
examples tend to leave white space on the right of the frame. I tried
basic a example with sizers and it didnt work. That why I was
wondering if someone had got it to work.
Roger

Hi Roger,
A key point is that the Grid manages itself its available space
according to the size it can have.
If you just tried to create a simple grid within a simple frame, you
probably got a grid filling all the frame space, and it's what you want.
Why that ?
If you do it (for instance with the script below), and you try to
manually reduce/increase the size of the window, you should see
scrollbars at the edge of the window ; these scrollbars come from the
grid, because they take in account the labels row and col (wxGrid comes
from wxScrolledWindo w). You can see that no more space is available
beyond the scrollbar, so the grid takes the whole space.
And why the white space on the right ? This space is not on the right of
the grid, but on the right of the last col. We could think it's like
that because it's not possible to compute an appropriate col size for
the grid cols, but it's not displayed exactly the same in linux and in
windows. In one case it's over the last col (not enough space) and in
the other case it's beyond (too much space). I think that as the program
must work on all the environments, the interface must stay enough
global, and sometimes the display is not perfectly done.
The advantage is that if we let wx decide, we won't have to think how to
set the widgets.
Regards,
jm

#----------------------------------------------------------------------
import wx,wx.grid
#----------------------------------------------------------------------
class MainWindow(wx.F rame):
def __init__(self,p arent,id,title) :
wx.Frame.__init __(self,parent, wx.ID_ANY,title )
#--
self.grid= wx.grid.Grid(id =wx.ID_ANY,pare nt=self)
self.grid.Creat eGrid(numRows=1 0,numCols=2)
self.grid.Fit()
self.Fit()
#--
self.Show(1)
#----------------------------------------------------------------------
app = wx.PySimpleApp( )
frame=MainWindo w(None,-1,'Grid sizer')
app.MainLoop()
del app
#----------------------------------------------------------------------


Thanks Tim,

I knew it was something like that, but I had to ask the question. I
was hoping that there was a way around the problem.

Roger

Jun 9 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
4190
by: Daniel Ehrenberg | last post by:
I'm trying to learn wxPython, but I can't seem to find much documentation. The wxPython website says that all advanced (and even some basic) documentation for wxPython is only available in C++ syntax in the main wxWindows documentation. It also says that the samples will help, but I can't seem to make sense of them. Should I just use a not-as-good GUI like Tkinter or a not-as-common one like Anygui or PyUI if I want to have documentation?...
1
2288
by: Martin Zuber | last post by:
Hello, I have found following problem: When I define event handler for EVT_NOTEBOOK_PAGE_CHANGED for wxNotebook, the content of the wxNotebook disappears (on all pages). For ex. I have two pages - one with some wxTextCtrls, second with some wxGrid. The dialog has been created using the Boa Constructor (0.2.3 and 0.2.7). I have two files: - SomeDialog.py - there is only look and events defined (we can say it
6
2841
by: Johnny Geling | last post by:
I would like use custom labelnames for rows in the wxGrid which I use through wxpython. The SetRowLabelValue from wxGridTableBase isn't doing anything. Is it posible to use custom rowlabels same as columnlabels? Johnny
5
10604
by: Andrew | last post by:
Hi I just started learning wxPython I wanted to know how I could do this in wxPython self.listbox.delete(0, END) for item in self.results: self.listbox.insert(END, item)
0
1575
by: Piet | last post by:
Hi there, I am currently developping a small app for the purpose mentioned above. The app connects to a MySQL database, can show the properties of tables (which are displayed as a wxGrid) and statements can be executed, the resuslts of which are also displayed in a wxGrid. Being a newbie, I wondered whether somebody has a similar project and wants to develop things together. My System: Win2000K, AMD AthlonXP2200+, Python 2.3.2, wxPython...
1
7081
by: matthiasjanes | last post by:
dear all, I just need a little help. could anyone give real code example (simple) how to read the value of a grid cell. i could not figure it out and really would like to do a simple spreadsheet application in wxpython (my first try with wxpython gui)
4
5368
by: Piet | last post by:
Hello. I am working on an XML editor that will not display the xml file as plain text, but will rather work with a combination of a tree view for the main element nodes and some kind of tabular view to view attributes. By this way, the user (i.e. me) will only have the opportunity to change textual contents and attribute values, but neither element nor attribute names. Building the tree view was not a problem, but I haven´t found a good...
1
1502
by: Sam the Cat | last post by:
using "from wxPython.wx import *" under python2.3 I cannot seem to find the wxGrid class -- it says its undefined -- am I missing something obvious ? I know the globalspace import is not the best, but that how I got started ;) -- any help owuld be appreciated
1
2375
by: Steven W. Orr | last post by:
python-2.3.5 wx-2.6 I just bought the wxPython In Action book and I see that all the examples say to import wx All of our pre-existing code was horribly doing a from wxPython import * I changed all the code so that it was doing an import wx and found that
0
8379
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8294
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8709
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7309
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4297
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1924
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1597
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.