logo
down
shadow

Parsing object attribute value to widget textvariable


Parsing object attribute value to widget textvariable

By : Nathan Taylor
Date : November 20 2020, 03:01 PM
this will help Normally we would make a variable in the common master, which is then passed down to the widgets. However you pass the root as a separate attribute. You should change that so that your main class is a subclass of tkinter.Tk:
Here's a small example:
code :
 import tkinter

class EofCanvas(tkinter.Canvas):
    def __init__(self, master, *args, **kwargs):
        tkinter.Canvas.__init__(self, master=master, *args, **kwargs)

        self.bind("<ButtonPress-1>", self.on_click)

    def on_click(self, event):
        self.master.status.set("CLICKED: {0.x}, {0.y}".format(event))

class UserInfoGame(tkinter.Frame):
    def __init__(self, master, coord, *args, **kwargs):
        tkinter.Frame.__init__(self, master=master, *args, **kwargs)

        label = tkinter.Label(self, width=50, textvariable=self.master.status) #<--- Here the textvariable
        label.pack()

class GameGUI(tkinter.Tk):
    def __init__(self, map_size, *args, **kwargs):
        tkinter.Tk.__init__(self, *args, **kwargs)

        self.status = tkinter.StringVar() # we make the variable in a place where all widgets can reach it

        canvas_game = EofCanvas(self, width=200, height=200, bg='white') # We pass "self", which includes all the instance variables
        user_info_game = UserInfoGame(self, bd=1, relief='ridge', coord=canvas_game)

        canvas_game.grid(column=1, row=1)
        user_info_game.grid(column=1, row=2)

if __name__ == '__main__':
    appstart = GameGUI(30) #the int spcifies the size of the board (int x int)
    appstart.mainloop()


Share : facebook icon twitter icon
Ruby Tk entry widget will not update textvariable

Ruby Tk entry widget will not update textvariable


By : tom ashby
Date : March 29 2020, 07:55 AM
this will help Text variables don't work this way. It appears you are trying to embed one textvariable into another. When you do "My name is #{name.get}.", it gets the value of the name variable at the time this statement is executed, it won't dynamically update.
If you want an entry widget and label to be kept in sync, they need to share the same variable.
Visible textvariable in tkinter Entry widget

Visible textvariable in tkinter Entry widget


By : ReDa EL Hazzat
Date : March 29 2020, 07:55 AM
I wish this helpful for you In order to use the textvariable attribute, you must give it an instance of a tkinter variable: StringVar, IntVar, BooleanVar, or DoubleVar
A good starting point to learn more about these variables is here: http://effbot.org/tkinterbook/variable.htm
How to update a Perl/Tk widget textvariable that is a moose attribute?

How to update a Perl/Tk widget textvariable that is a moose attribute?


By : Ben Rejeb Zied
Date : March 29 2020, 07:55 AM
wish helps you Make the accessors private, and then provide a wrapper for the accessor. Something like this:
code :
subtype 'TkRef', as 'ScalarRef';
coerce 'TkRef', from 'Str', via { my $r = $_; return \$r };

has _some_val => (
   is       => 'rw',
   isa      => 'TkRef',
   coerce   => 1,
   init_arg => 'some_val',
   default  => 'default value',
);

sub some_val {
   my $self = shift;
   if (@_ and not ref $_[0]) {
      ${$self->_some_val} = shift;
   }
   elsif (@_ and ref $_[0]) {
      ${$self->_some_val} = ${+shift};
   }
   $self->_some_val(@_);
}
tkinter entry widget textvariable will not update with .set method

tkinter entry widget textvariable will not update with .set method


By : kwok
Date : March 29 2020, 07:55 AM
hope this fix your issue You cannot create more than once instance of Tk, because of exactly this type of behavior. If you need a new window, create an instance of Toplevel.
Python tkinter textvariable in label widget

Python tkinter textvariable in label widget


By : Spiderman
Date : March 29 2020, 07:55 AM
it fixes the issue Edit: The solution to the original post was using text=localtime2.get() instead of textvariable=localtime2 in the label widget (for some strange reason). However, my original answer is still correct as tkinter variables should be used and so I will keep it up.
code :
string_variable = tk.StringVar()
boolean_variable = tk.BooleanVar()
string_variable = tk.StringVar() # Create the variable 
string_variable.set("a string") # Set the value of the variable
localtime2 = tk.StringVar() # Create the localtime2 string variable
localtime2.set(time.asctime(time.localtime(time.time()))) # Set the variable
tk.Label(roots, font=('arial', 16, 'bold'), textvariable=localtime2, bd=16, anchor="w").grid(row=2, column=0)
Related Posts Related Posts :
  • Key search in a dictionary
  • Writing to files in ASCII with Python3, not UTF8
  • Web Scraping: Page exists but getting 404 using requests/urllib
  • Using enter in an if statement
  • How to plot vertical lines in plotly offline?
  • padding MNIST dataset with tf.pad()
  • Fitting multiple gaussian using **curve_fit** function from scipy using python 3.x
  • Seaborn barplot wrong order when using numbers in factor even its type is string
  • How to code win/tie conditions in TicTacToe game in python
  • how to get status code other than 200 from scrapy-splash
  • Python 3 .format and List
  • QWidget raise above matplotlib canvas
  • Types conditions on python after an input
  • formatting integers in pivot_table
  • Python return a list of lists of combinations of sequence
  • Independent Indexing in pandas.DataFrame
  • Import csv file with sep=';' to python by columns - Pandas Dataset
  • Byte-encoding IP address in Python 3 and converting back to string
  • smooth bezier equivalent plotting in matplotlib
  • Sympy TypeError: cannot determine truth value of Relational when using sympy
  • Erroneous Output for Path Check in Python 3.6
  • PyYAML can't load from file but can write
  • Eliminate string elements in a list with double 'a'
  • Merge and then sort columns of a dataframe based on the columns of the merging dataframe
  • Seaborn right ytick
  • Bokeh Plots Axis Value don't show completely
  • Problems when creating Game Board: prints too many lists
  • Click item on hover menu with Selenium webdriverusing python
  • Change string to a date format in python 3
  • calling help(MyClass) also shows base class attributes: how to avoid that?
  • Confused about static class vars in python
  • Why can't I plot multiple scatter subplots in one figure for a data set from a DataFrame of Pandas (Python) in the way I
  • How to use discord bot commands and event both?
  • Python3 - print string and list
  • Running sums from one column conditional on values in another column
  • How to create dictionary combinations? Costliest car problem
  • Select each letter in a file, then find its ASCII value (Python)
  • Python: logarithm to base 2 in nested lists
  • Knapsack algorithm, weird behavior (python3)
  • How to use the break between lines in a txt file to start a new list in Python 3
  • Default *key* when accessing dictionary?
  • "TypeError: a bytes-like object is required, not 'str'" during OAuth 2.0 callback request
  • Lat Long won't show on Heatmap with ipyleaflet
  • Python Flask paginate error:paginated page returned 404
  • can't pickle _thread.RLock objects when running tune of ray packge for python (hyper parameter tuning)
  • Python 3: Positions of button and input text in a text box
  • Bijective function between two nested lists (Python)
  • How to get python console logs on my tkinter window instead of a CMD window while executing an exe file created using py
  • how combine '"+variable+"' in python 3
  • Year wise cumsum based on condition on other column Python 3+ Pandas data frame
  • How to send a message with discord.py from outside the event loop (i.e. from python-telegram-bot thread)?
  • BytesIO replaces transparency in PNG files with black background
  • Cannot resize and save image of type .tif after patch extraction with tf
  • Pandas Column Names Not Lining Up When .dat File Read
  • Adding an Image to the python GUI from within the script
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org