473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Label position on Homebrew Pmw Megawidget

I'm trying to create a megawidget for file selection that contains a
Label, EntryField, and Browse Button (that will open a tkFileDialog).
The label positioning won't cooperate however, could anyone help with
this?

Here's what I want:
labelpos='w':
---------------------- ------------
Filename: |c:\directory\file | |Browse... |
---------------------- ------------

No matter what I set as labelpos, the label will not end up on the
same row as the other widgets. Some others are also not working as
expected:

labelpos='w':
---------------------- ------------
|c:\directory\file | |Browse... |
---------------------- ------------
Filename:

My code is below. I've tried different grid(row,column) values for
the widgets, but that didn't seem to help.
Can anyone help with this? It's driving me nuts! I imagine I'm doing
something wrong with the createlabel() method, or something else
trivially simple...

------------- cut here -------------------------------
#!/bin/python
#Running standalone will demo the above ascii pic, plus some others:

import Pmw
import Tkinter
from Tkinter import *
import tkFileDialog

class FileSelect(Pmw.MegaWidget):
""" Megawidget containing Pmw.Entryfield and a Browse button
for file selection
"""

def __init__ (self, parent=None, **kw):
# Define the megawidget options
optiondefs = (
('labelmargin', 0, Pmw.INITOPT),
('labelpos', None, Pmw.INITOPT),
)
self.defineoptions(kw, optiondefs)

# Initialise base class (after defining options)
Pmw.MegaWidget.__init__(self, parent)

# Create the components
interior = self.interior()

# Create a label
self.createlabel(interior, childRows=2, childCols=1)

# Create the Entryfield component
self.entryfield = self.createcomponent('filename', # Name
(), # Aliases
None, # Group
Pmw.EntryField, # Class
(interior,), #
Constructor Args
)
self.entryfield.grid(row=1, column=1)

# Create the Browse Button
self.browsebutton = self.createcomponent('browsebutton', # Name
(), # Aliases
None, # Group
Tkinter.Button, # Class
interior, #
Constructor Args
text="Browse...",
command=self.getFileName
)
self.browsebutton.grid(row=1, column=2)

# Check keywords and initialise options
self.initialiseoptions()

#------------------------------------------------------------------
# Popup a file select dialog and fill in the entry field with the
# chose filename
#------------------------------------------------------------------

def getFileName (self):
dialog = tkFileDialog.Open()
fname = dialog.show()
if fname != "":
self.entryfield.setvalue(fname)

# Standalone demo
if __name__ == "__main__":
root = Tkinter.Tk()

# Create and pack a FileSelect widgets
widgets = []

widgets.append(FileSelect(labelpos='n', label_text="north"))
widgets.append(FileSelect(labelpos='e', label_text="east"))
widgets.append(FileSelect(labelpos='s', label_text="south"))
widgets.append(FileSelect(labelpos='w', label_text="west"))
widgets.append(FileSelect(labelpos='ws', label_text="westsouth"))
widgets.append(FileSelect(labelpos='wn', label_text="westnorth"))
widgets.append(FileSelect(labelpos='sw', label_text="southwest"))
widgets.append(FileSelect(labelpos='nw', label_text="northwest"))

map(lambda w: w.pack(pady=20), widgets)
root.mainloop()

------------- cut here -------------------------------
Jul 18 '05 #1
1 1803
Greg wrote:
I'm trying to create a megawidget for file selection that contains a
Label, EntryField, and Browse Button (that will open a tkFileDialog).
The label positioning won't cooperate however, could anyone help with
this?

Here's what I want:
labelpos='w':
---------------------- ------------
Filename: |c:\directory\file | |Browse... |
---------------------- ------------
[...]
My code is below. I've tried different grid(row,column) values for
the widgets, but that didn't seem to help.
Can anyone help with this? It's driving me nuts! I imagine I'm doing
something wrong with the createlabel() method, or something else
trivially simple...


I've no clue either. Enter brute force:

#!/bin/python
#Running standalone will demo the above ascii pic, plus some others:

import Pmw
import Tkinter
from Tkinter import *
import tkFileDialog

class FileSelect(Pmw.MegaWidget):
""" Megawidget containing Pmw.Entryfield and a Browse button
for file selection
"""

def __init__ (self, parent=None, **kw):
# Define the megawidget options
optiondefs = (
('labelmargin', 0, Pmw.INITOPT),
('labelpos', None, Pmw.INITOPT),
)
self.defineoptions(kw, optiondefs)

# Initialise base class (after defining options)
Pmw.MegaWidget.__init__(self, parent)

# Create the components
interior = self.interior()

# Create a label
self.createlabel(interior, childRows=2, childCols=1)

# Create the Entryfield component
self.entryfield = self.createcomponent('filename', # Name
(), # Aliases
None, # Group
Pmw.EntryField, # Class
(interior,), # Constructor
Args
)
self.entryfield.grid(row=yoff, column=xoff)

# Create the Browse Button
self.browsebutton = self.createcomponent('browsebutton', # Name
(), # Aliases
None, # Group
Tkinter.Button, # Class
interior, # Constructor
Args
text="Browse...",
command=self.getFileName
)
self.browsebutton.grid(row=yoff, column=xoff+1)

# Check keywords and initialise options
self.initialiseoptions()

#------------------------------------------------------------------
# Popup a file select dialog and fill in the entry field with the
# chose filename
#------------------------------------------------------------------

def getFileName (self):
dialog = tkFileDialog.Open()
fname = dialog.show()
if fname != "":
self.entryfield.setvalue(fname)

xoff = 0
yoff = 0

def terminate():
import sys
sys.exit(0)

def testWidgets():
root = Tkinter.Tk()

# Create and pack a FileSelect widgets
widgets = []
Tkinter.Button(root, text="terminate app", command=terminate).pack()
Tkinter.Button(root, text="next try", command=root.quit).pack()
widgets.append(FileSelect(labelpos='n', label_text="north"))
widgets.append(FileSelect(labelpos='e', label_text="east"))
widgets.append(FileSelect(labelpos='s', label_text="south"))
widgets.append(FileSelect(labelpos='w', label_text="west"))
widgets.append(FileSelect(labelpos='ws', label_text="westsouth"))
widgets.append(FileSelect(labelpos='wn', label_text="westnorth"))
widgets.append(FileSelect(labelpos='sw', label_text="southwest"))
widgets.append(FileSelect(labelpos='nw', label_text="northwest"))

map(lambda w: w.pack(pady=20), widgets)
return root

if __name__ == "__main__":
for xoff in range(3):
for yoff in range(3):
root = testWidgets()
root.title("Testing xoff=%d, yoff=%d" % (xoff, yoff))
root.mainloop()
root.destroy()

(xoff=1, yoff=2) seems promising.

Peter
Jul 18 '05 #2

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

Similar topics

0
by: Jacky11 | last post by:
By default when you enable the data label in a 3-D Bar Chart, the data label starts in the middle of the bar chart. There is no Label Position option for a 3-D Chart, like nay other chart type....
4
by: Stuart Norris | last post by:
Dear Readers, I am attempting to draw box around some text using unicode on multiline label. The label is forty characters wide and 12 lines deep. I have been trying to draw a box around text...
1
by: gce | last post by:
I like to declare my label in the code : dim lblTotaal as new label And then I like to place it on an exact position. When I type the following in the HTML part it works, but I like to have my code...
2
by: Joe Delphi | last post by:
Hi, I want to position label text so that it always appears centered when the user re-sizes the browser window. I tried adding the HTML property text-align="CENTER" to the code, but ASP.NET...
8
by: david | last post by:
I have developed a web form by using visual Studio. My question is: (1) what is the problem? (2) what is right way to do it? In the form, there are labels with id: lblWear, lblColor, and...
1
by: Al in Dallas | last post by:
I'm new to Python*. I am having trouble with the Tix NoteBook megawidget. When I use a simpler megawidget, such as a ButtonBox, I can add buttons by invoking <nameOfButtonBox>.add ('button3',...
9
by: Haines Brown | last post by:
I would like to have a label followed by a line to the right margin, such as this: Label: _____________________________________________________________ There are ways to define lines having...
2
by: Wilfried Mestdagh | last post by:
Hi, I want to add a Label on a panel programatically. No problem. But I can't seems to manage that the label is centered horizontal and vertical in the panel. I experimented with TextAlign and...
4
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
I have two labels on a form. The text for these two labels is assigned at runtime. lblLeft lblRight If the text for lblLeft is wider than the default, the text runs into lblRight. How do...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.