473,769 Members | 2,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\f ile | |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\f ile | |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.defineopti ons(kw, optiondefs)

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

# Create the components
interior = self.interior()

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

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

# Create the Browse Button
self.browsebutt on = self.createcomp onent('browsebu tton', # Name
(), # Aliases
None, # Group
Tkinter.Button, # Class
interior, #
Constructor Args
text="Browse... ",
command=self.ge tFileName
)
self.browsebutt on.grid(row=1, column=2)

# Check keywords and initialise options
self.initialise options()

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

def getFileName (self):
dialog = tkFileDialog.Op en()
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(labe lpos='n', label_text="nor th"))
widgets.append( FileSelect(labe lpos='e', label_text="eas t"))
widgets.append( FileSelect(labe lpos='s', label_text="sou th"))
widgets.append( FileSelect(labe lpos='w', label_text="wes t"))
widgets.append( FileSelect(labe lpos='ws', label_text="wes tsouth"))
widgets.append( FileSelect(labe lpos='wn', label_text="wes tnorth"))
widgets.append( FileSelect(labe lpos='sw', label_text="sou thwest"))
widgets.append( FileSelect(labe lpos='nw', label_text="nor thwest"))

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

------------- cut here -------------------------------
Jul 18 '05 #1
1 1819
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\f ile | |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.defineopti ons(kw, optiondefs)

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

# Create the components
interior = self.interior()

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

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

# Create the Browse Button
self.browsebutt on = self.createcomp onent('browsebu tton', # Name
(), # Aliases
None, # Group
Tkinter.Button, # Class
interior, # Constructor
Args
text="Browse... ",
command=self.ge tFileName
)
self.browsebutt on.grid(row=yof f, column=xoff+1)

# Check keywords and initialise options
self.initialise options()

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

def getFileName (self):
dialog = tkFileDialog.Op en()
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=termina te).pack()
Tkinter.Button( root, text="next try", command=root.qu it).pack()
widgets.append( FileSelect(labe lpos='n', label_text="nor th"))
widgets.append( FileSelect(labe lpos='e', label_text="eas t"))
widgets.append( FileSelect(labe lpos='s', label_text="sou th"))
widgets.append( FileSelect(labe lpos='w', label_text="wes t"))
widgets.append( FileSelect(labe lpos='ws', label_text="wes tsouth"))
widgets.append( FileSelect(labe lpos='wn', label_text="wes tnorth"))
widgets.append( FileSelect(labe lpos='sw', label_text="sou thwest"))
widgets.append( FileSelect(labe lpos='nw', label_text="nor thwest"))

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("Tes ting 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
1342
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. I would like to have the label at the "Outside End Position". Does any one know of any fix, or of any Addin tool? I found a wonderful addin that works only with Excel.
4
12344
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 (centered in the label) on this label. My font on this label is Courier new - hence fixed width character cells.
1
1318
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 do the trick. Please help <asp:Label id="lblTotaal" style="Z-INDEX: 103; LEFT: 500px; POSITION: absolute; TOP: 500px" runat="server" Height="16px" Width="112px">lblTotaal</asp:Label>
2
2652
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 doesn't seem to recognize this HTML attribute. Can someone tell me how to do this?
8
3767
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 lblQuality. Now I need to assign values to those label dynamically. I have JavaScript: function regTriples(id){ if (id==1){
1
2106
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', text='Retry') Unfortunately, with the Notebook, I need access to a subwidget, and all my attempts have led to error messages. When I try to look up the megawidget documentation, I can only find example in Tcl, so I'm confident that if someone...
9
7107
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 specific length, but I wanted one that would have variable length, surviving a change in display window size or font. I came up with the ugly markup below. It looks OK in a browser, but for some reason the line disappears when I print it.
2
20538
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 Dock but no real success. I probably forget something. Some hints really welcome :) -- rgds, Wilfried http://www.mestdagh.biz
4
6544
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 I make lblLeft automatically expand to the left?
0
9586
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
10043
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...
1
9990
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8869
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...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
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.