Search Results

Search found 4 results on 1 pages for 'sano98'.

Page 1/1 | 1 

  • Python Tkinter Tix: How to use ScrolledWindow with grid in Tix NoteBook

    - by Sano98
    Hi guys, I'm adding several widgets to a Frame which is located in a tix.NoteBook. When there are too much widgets to fit in the window, I want to use a scrollbar, so I put tix.ScrolledWindow inside that Frame and add my widgets to this ScrolledWindow instead. The problem is that when using the grid() geometry manager, the scrollbar appears, but it is not working (The drag bar occupies the whole scroll bar). from Tkinter import * import Tix class Window: def __init__(self, root): self.labelList = [] self.notebook = Tix.NoteBook(root, ipadx=3, ipady=3) self.notebook.add('sheet_1', label="Sheet 1", underline=0) self.notebook.add('sheet_2', label="Sheet 2", underline=0) self.notebook.add('sheet_3', label="Sheet 3", underline=0) self.notebook.pack() #self.notebook.grid(row=0, column=0) tab1=self.notebook.sheet_1 tab2=self.notebook.sheet_2 tab3=self.notebook.sheet_3 self.myMainContainer = Frame(tab1) self.myMainContainer.pack() #self.myMainContainer.grid(row=0, column=0) scrwin = Tix.ScrolledWindow(self.myMainContainer, scrollbar='y') scrwin.pack() #scrwin.grid(row=0, column=0) self.win = scrwin.window for i in range (100): self.labelList.append((Label(self.win))) self.labelList[-1].config(text= "Bla", relief = SUNKEN) self.labelList[-1].grid(row=i, column=0, sticky=W+E) root = Tix.Tk() myWindow = Window(root) root.mainloop() Whenever I change at least one of the geometry managers from pack() to grid(), the problem occurs. (Actually, I'd prefer using grid() for all containers.) When I don't use the NoteBook widget, the problem does not occur either. The other examples here all seem to rely on pack(). Any ideas? Many thanks, Sano

    Read the article

  • Python: Inheritance of a class attribute (list)

    - by Sano98
    Hi everyone, inheriting a class attribute from a super class and later changing the value for the subclass works fine: class Unit(object): value = 10 class Archer(Unit): pass print Unit.value print Archer.value Archer.value = 5 print Unit.value print Archer.value leads to the output: 10 10 10 5 which is just fine: Archer inherits the value from Unit, but when I change Archer's value, Unit's value remains untouched. Now, if the inherited value is a list, the shallow copy effect strikes and the value of the superclass is also affected: class Unit(object): listvalue = [10] class Archer(Unit): pass print Unit.listvalue print Archer.listvalue Archer.listvalue[0] = 5 print Unit.listvalue print Archer.listvalue Output: 10 10 5 5 Is there a way to "deep copy" a list when inheriting it from the super class? Many thanks Sano

    Read the article

  • Python: Class factory using user input as class names

    - by Sano98
    Hi everyone, I want to add class atttributes to a superclass dynamically. Furthermore, I want to create classes that inherit from this superclass dynamically, and the name of those subclasses should depend on user input. There is a superclass "Unit", to which I can add attributes at runtime. This already works. def add_attr (cls, name, value): setattr(cls, name, value) class Unit(object): pass class Archer(Unit): pass myArcher = Archer() add_attr(Unit, 'strength', 5) print "Strenght ofmyarcher: " + str(myArcher.strength) Archer.strength = 2 print "Strenght ofmyarcher: " + str(myArcher.strength) This leads to the desired output: Strenght ofmyarcher: 5 Strenght ofmyarcher: 2 But now I don't want to predefine the subclass Archer, but I'd rather let the user decide how to call this subclass. I've tried something like this: class Meta(type, subclassname): def __new__(cls, subclassname, bases, dct): return type.__new__(cls, subclassname, Unit, dct) factory = Meta() factory.__new__("Soldier") but no luck. I guess I haven't really understood what new does here. What I want as a result here is class Soldier(Unit): pass being created by the factory. And if I call the factory with the argument "Knight", I'd like a class Knight, subclass of Unit, to be created. Any ideas? Many thanks in advance! Bye -Sano

    Read the article

  • Python TKinter connect variable to entry widget

    - by Sano98
    Hi everyone, I'm trying to associate a variable with a Tkinter entry widget, in a way that: Whenever I change the value (the "content") of the entry, mainly by typing something into it, the variable automatically gets assigned the value of what I've typed. Without me having to push a button "Update value " or something like that first. Whenever the variable gets changed (by some other part of the programm), I want the entry value displayed to be adjusted automatically. I believe that this could work via the textvariable. I read the example on http://effbot.org/tkinterbook/entry.htm, but it is not exactly helping me for what I have in mind. I have a feeling that there is a way of ensuring the first condition with using entry's "validate". Any ideas? Thank you for your input! Sano

    Read the article

1