Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have 1 main window and 1 dialog. Now I need to access variable in main window from dialog.

For example in java we have 2 classes: demo and myclass In my class I have following code: public static int number=5; Then I simply access it using myclass.number.

How to do it in python using quickly ide?

Do I need to import main window in dialog to get access to static variable?

share|improve this question
I have no idea what quickly is but first of all you wouldn't normally declare a variable public in Java but private (or protected). Second I think that in python you would do import myclass in your other class, then you would instantiate it m=myclass() and should be able to access it m.number. You can also acccess it without instantiation. See… for further information. – onse Jul 3 '12 at 20:09
To make example more simple I put public :D – user26030 Jul 3 '12 at 21:28

Just pass around your mainwindow instance, something like this:

class MyWindow(Gtk.Window):
    def __init__(self):
        # Do your thing...

        self.spam = "spam'n'eggs"

    def on_opendialog_clicked(self, widget):
        dialog = MyDialog(self)

class MyDialog(Gtk.Dialog):
    def __init__(self, mainwindow):
        # ...


Have a look at my answer in this question too which is almost similar, only the other way around.

share|improve this answer
Error is on line: dialog = MyDialog(self) – user26030 Jul 3 '12 at 22:46
Here you can see the code generated by quickly which probably causes error: – user26030 Jul 3 '12 at 22:51
Please provide an actual traceback. "Probably" and "error" aren't of any help. – Timo Jul 4 '12 at 7:41
TypeError: Must be string, not SampleWindow Here you can find sample application: – user26030 Jul 4 '12 at 16:56

I'm not sure if this is the "pro" way to do it or not, but you can pass it to your variable when you generate it.

I have a file generation dialog I built by giving it the default output dir and default name of file. My code looks like:def __init__(self,parent,output_dir,filename), and when you call it make sure to pass it what it needs, eg. window(output_dir,filename)

share|improve this answer
Here is my I dont have init – user26030 Jul 4 '12 at 16:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.