Newbie Question

S

solaris_1234

I am trying to learn Python and I have a few questions.

I have created a Class that is essentially a canvas with a red
background. After creation I want to change the background to green.
However I am having problems doing this.

Here is my code:

from Tkinter import *

class MyApp:
def __init__(self, parent):
self.myParent = parent
self.myContainer = Frame(parent)
self.myContainer.pack()

self.b1 = Canvas(self.myContainer, background="red").grid(row=0,
column=0)

def ChangebgColor(self):
self(bg="green")


root = Tk()
myapp=MyApp(root) #Everything is fine at this point.

raw_input()

ChangebgColor(myapp.b1) # Error Message at this point

raw_input()



Any help will be greatly appreciated.
 
K

kyle.tk

solaris_1234 said:
I am trying to learn Python and I have a few questions.

I have created a Class that is essentially a canvas with a red
background. After creation I want to change the background to green.
However I am having problems doing this.

Here is my code:

from Tkinter import *

class MyApp:
def __init__(self, parent):
self.myParent = parent
self.myContainer = Frame(parent)
self.myContainer.pack()

self.b1 = Canvas(self.myContainer, background="red").grid(row=0,
column=0)

def ChangebgColor(self):
self(bg="green")


root = Tk()
myapp=MyApp(root) #Everything is fine at this point.

raw_input()

ChangebgColor(myapp.b1) # Error Message at this point

raw_input()



Any help will be greatly appreciated.

here ya go.

from Tkinter import *

class MyApp:
def __init__(self, parent):
self.myParent = parent
self.myContainer = Frame(parent)
self.myContainer.pack()
self.b1 = Canvas(self.myContainer, background="red")
self.b1.grid(row=0,column=0)

def ChangebgColor(self):
self.b1.config(bg="green")

root = Tk()
myapp=MyApp(root)
raw_input()
myapp.ChangebgColor()
raw_input()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,828
Latest member
LauraCastr

Latest Threads

Top