Guido Carballo-Guerrero | 1 Jun 04:30 2010

How can I change the font in a heading using treeview

Hello;

Can somebody tell me how can I change the font size in the headings of a treeview table. I could change the
fonts color and size of the data inside of the table, but I haven't been able to change the heading's font.

Guido
Sibylle Koczian | 1 Jun 16:43 2010
Picon

Using listvariable in listbox - how?


___________________________________________________________
NEU: WEB.DE DSL für 19,99 EUR/mtl. und ohne Mindest-Laufzeit!
http://produkte.web.de/go/02/
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss <at> python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss
Sibylle Koczian | 1 Jun 16:52 2010
Picon

Using listvariable in listbox - how?

Hello,

I'm trying to understand how to use a tkinter listbox. It should show a list of strings; the selected string should be transferred into an entry field where it can be edited and written back into the listbox.

At the moment I'm just trying to read and change listbox entries programmatically. Here is the first attempt:

# listbox_mini.py

import tkinter as tk
from tkinter import ttk

# *** see (a)
cFlowers = ("Iberis sempervirens", "Geranium macrorrhizu", "Nemesia Sunsatia",
            "Iris Barbata Nana")

class MainWindow(ttk.Frame):

     def __init__(self, master=None):
         super().__init__(master)
         top = self.winfo_toplevel()
         top.rowconfigure(0, weight=1)
         top.columnconfigure(0, weight=1)
         self.rowconfigure(0, weight=1)
         self.columnconfigure(0, weight=1)
         self.grid(sticky="nsew")
         self.createListboxFrame(cFlowers)

     def createListboxFrame(self, vals):
         lboxfr = ttk.Frame(self)
         lboxfr.rowconfigure(0, weight=1)
         lboxfr.columnconfigure(1, weight=1)
         lboxfr.grid(sticky="nsew")
         lb = ttk.Label(lboxfr, text='Flowers')
         lb.grid(padx=5, pady=5)
         # *** next two lines: see (b)
         # self.flowers = tk.Variable(value=vals)
         self.flowers = tk.StringVar(value=vals)
         self.flowerbox = tk.Listbox(lboxfr, listvariable=self.flowers, height=5)
         self.flowerbox.grid(row=0, column=1, padx=5, pady=5, sticky="nsew")
         self.flowerbox.bind("<<ListboxSelect>>", self.doEdit)

    def doEdit(self, evt):
         print(self.flowerbox.curselection())
         idx = self.flowerbox.curselection()[0]
         # *** next two lines: see (b)
         # xx = self.flowers.get()[int(idx)]
         xx = self.flowerbox.get(idx)
         print(repr(xx))
         # self.flowers[int(idx)].set(xx + '**')
         # *** TypeError: "StringVar" object (or "Variable object")
         # *** does not support indexing
         # self.flowerbox.set(idx, xx + '**')
         # *** AttributeError: "Listbox" object has no attribute "set"
         self.flowerbox.delete(idx)
         self.flowerbox.insert(idx, xx + '**')
         print(repr(self.flowers.get()))

def main():

    mw =
MainWindow()
    mw.master.title("Listbox and listvariable")
    mw.mainloop()

if __name__ == '__main__':
    main()


Questions about this:


(a) If and only if cFlowers is a tuple the elements of this tuple are shown as lines in the listbox. If it's a list the lines in the listbox are the elements of the list returned by repr(cFlowers).split(). Why?

(b) If self.flowers is a tk.StringVar() then self.flowers.get()[int(idx)] doesn't return the listbox entry at index idx, but the character at index idx in the string repr(cFlowers). If it's a tk.Variable(), then this construction returns the listbox entry. But it is quite ugly, anyway. The other line, "xx = self.flowerbox.get(idx)" always returns the listbox entry.

(c) Replacing a listbox entry only seems to be possible by deleting the old and inserting the new one. Why? And only with listbox methods, not by working with the listvariable.

I suppose it would be possible to do any changes to the list using cFlowers directly (as a list, not as a tuple, of course) and replacing the entire self.flowers by the changed version, converted to a tuple, as often as necessary.

But all of this leads to the question: why use the listvariable at all? Or what other tkinter control would be better for my purpose?

Googling only showed some older quite similar questions without answers.

Using Python 3.1.2 with Tcl/tk 8.5, tkinter revision 73084.

Thank you for explanations,
Sibylle

  

GRATIS für alle WEB.DE Nutzer: Die maxdome Movie-FLAT!   
Jetzt freischalten unter http://movieflat.web.de
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss <at> python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss
Gary Scorby | 1 Jun 17:15 2010

Re: OptionMenu text justification

I guess I didn't explain this very well.

I attempting to use Tkinter OptionMenu as a dropdown list.  After picking the desired text in the dropdown
list the text is centered in the window.  I would like it to be left justified.  Nothing I have tried has been
successful.  I am not talking about the label.  I am not talking about text entered by hand.  I am talking about
the text in the dropdown list after a selection is made from that list.

Thanks

Gary

-----Original Message-----
From: John McMonagle [mailto:jmcmonagle <at> velseis.com] 
Sent: Sunday, May 30, 2010 4:12 PM
To: Gary Scorby
Cc: tkinter-discuss <at> python.org
Subject: Re: [Tkinter-discuss] OptionMenu text justification

Gary Scorby wrote:
> I’m new to Tkinter.  I need a drop down box to display a selection list
> to an end user.  It appears the best option for this is “OptionMenu” (If
> not, please suggest other options).  I have it working like we want
> except for one thing, after selecting something from the list and
> closing the list, the text is centered in the window.  We have some very
> long lines of text to choose from.  When the choice is made we would
> like the chosen text to be left justified in the window.  I’ve tried
> ever option I can find, but the text remains centered.  Any assistance
> will be appreciated.
> 
>  

In what widget are you displaying the text ?   Label, Entry, Text ?


For example, the following code displays two labels with varying lengths
of text, aligned to the left:

from Tkinter import *
r = Tk()
t1 = 'Short text'
t2 = 'Long line of meaningless text to illustrate problem'
l1 = Label(r, text=t1)
l2 = Label(r, text=t2)

l1.pack(anchor=W)
l2.pack(anchor=W)

r.mainloop()

Now, if you wish to restrict the text to some horizontal distance and
keep it left justified, you would use wraplength=distance, justify=LEFT
as extra options to the Label widget.

I hope this provides some assistance.

Regards,

John

_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss <at> python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss
Michael Lange | 1 Jun 19:05 2010
Picon

Re: OptionMenu text justification

Hi Gary,

On Tue, 1 Jun 2010 08:15:31 -0700
Gary Scorby <Gary.Scorby <at> harlandfs.com> wrote:

> I guess I didn't explain this very well.
> 
> I attempting to use Tkinter OptionMenu as a dropdown list.  After
> picking the desired text in the dropdown list the text is centered in
> the window.  I would like it to be left justified.  Nothing I have
> tried has been successful.  I am not talking about the label.  I am
> not talking about text entered by hand.  I am talking about the text
> in the dropdown list after a selection is made from that list.
> 

Maybe

   option_menu.configure(anchor='w')

does what you want? Here this puts all the widget's text to the left of
the menubutton. If you want to additionally left-justify multi-lined
text you need also justify='left' .

I hope this helps

Michael
Krb686 | 1 Jun 22:43 2010
Picon

Tkinter - Drawing Webcam Images?


I'm pretty new to Python and Tkinter, so there might be an easier or more
advanced way of doing this that I don't know of, but bear with me.  I'm
making a simple webcam gui using VideoCapture and PIL, and I realized that
to get the video working you must retrieve and display the images in a loop
on the gui, but you can't do this normally without threading because then
the gui won't update any more, or at least as far as I know.  So I need some
help on this if anyone knows an easier way to do this without threading. 
And is it possible to allow your own code to run within the tkinter
mainloop? Because then I could just allow it to update with the gui mainloop
and not use threading.
--

-- 
View this message in context: http://old.nabble.com/Tkinter---Drawing-Webcam-Images--tp28747239p28747239.html
Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.
Vasilis Vlachoudis | 2 Jun 09:16 2010
Picon
Picon

Drop events from Desktop

Hi all,

 

Is there a way in Tkinter to receive drag’n’drop events from the Desktop?

e.g. from the filemanager drag a file in a Tkinter application

 

Regards

Vasilis

_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss <at> python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss
Michael Lange | 2 Jun 11:23 2010
Picon

Re: Tkinter - Drawing Webcam Images?

Hi,

On Tue, 1 Jun 2010 13:43:08 -0700 (PDT)
Krb686 <Krb686 <at> gmail.com> wrote:

> 
> I'm pretty new to Python and Tkinter, so there might be an easier or
> more advanced way of doing this that I don't know of, but bear with
> me.  I'm making a simple webcam gui using VideoCapture and PIL, and I
> realized that to get the video working you must retrieve and display
> the images in a loop on the gui, but you can't do this normally
> without threading because then the gui won't update any more, or at
> least as far as I know.  So I need some help on this if anyone knows
> an easier way to do this without threading. And is it possible to
> allow your own code to run within the tkinter mainloop? Because then
> I could just allow it to update with the gui mainloop and not use
> threading.

Maybe you could use a loop with after() calls and update_idletasks() to
update the image, like this simple example:

def update_loop():
    update_image()
    somewidget.update_idletasks()
    somewidget.after(100, update_loop)

With a useful update_image() method you just need to enter the loop
once and it should do what you want.

I hope this helps

Michael
Michael Lange | 2 Jun 11:28 2010
Picon

Re: Drop events from Desktop

Hi,

On Wed, 2 Jun 2010 09:16:01 +0200
Vasilis Vlachoudis <Vasilis.Vlachoudis <at> cern.ch> wrote:

> Hi all,
> 
>  
> 
> Is there a way in Tkinter to receive drag'n'drop events from the
> Desktop?
> 
> e.g. from the filemanager drag a file in a Tkinter application
> 
>  

You can try the tkdnd Tk extension from

    http://sourceforge.net/projects/tkdnd/files/

and the respective Tkinter wrappers from http://klappnase.bubble.org/

However, your mileage may vary, depending on the platform (Windows /
Mac /Linux) in use. 

I hope this helps

Michael
Ma China | 3 Jun 10:34 2010
Picon

problems of Tix.FileEntry and tkMessageBox in WinXP

Hi, friends
  I'm programming with Tkinter/Tix. I want to use Tix.FileEntry, and only find fe_obj['value'] to get the selected file, is there any other way? As I find it may cause some memory problems, while used with tkMessageBox.
  Running the following codes, if I click "Work" twice, the program will crash before the 2nd warning sub-window pops up. Even if I comment the 2 lines of adding Label self.sflb, it still dump.
 
  My pc is WinXP Version 2002 Service Pack 3, CPU is Intel Core2 2-core, with Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32.
  I find it may be due to conflicts with Tix.FileEntry. How to fix it?

import Tkinter, Tix
import tkMessageBox, tkFileDialog
class Worker():
    def __init__(self):
        self.root = Tix.Tk()
        self.sffm = Tkinter.Frame(self.root)
        self.sflb = Tkinter.Label(self.sffm, text='Select file        :')
        self.sflb.pack(side='left')
        self.sfft = Tix.FileEntry (self.sffm)
        self.sfft.pack(side='left')
        self.btfm = Tkinter.Frame(self.root)
        self.gnbt = Tkinter.Button(self.btfm,text='Work', command=self.work)
        self.gnbt.pack(side='left')
        self.sffm.pack()       
        self.btfm.pack()
        Tkinter.mainloop()
       
    def work(self) :
        ''' do all work '''
        print 1
        value = self.sfft["value"]
        # use showwarning/showerror, if click "Work' for 2 times, will dump
        tkMessageBox.showwarning('Title', '<%s>' % value)
       
        print '+%s+' % value
       
if __name__=='__main__':
    worker = Worker()
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss <at> python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss

Gmane