简体   繁体   中英

AttributeError: 'module' object has no attribute 'start' (wxPython)

I am making a simple text editor to get the basics of GUI programming. I am using wxPython.

When I run main.py , a window will pop up with the buttons READ and WRITE, READ being for opening and reading files, and WRITE being for editing files. The wx.Frame classes for those are in read.py and write.py respectively.

The function k() works fine, there is no error with write.write() , but I get an AttributeError with read.read() , which I had originally in l() .

I changed the line to read.start() , and in read.py I added the function start() which makes an instance of the class read , because I thought that maybe it wasn't executing because it was a class, just to be sure.

Still, I am getting the error: AttributeError: 'module' object has no attribute 'start'

main.py

import wx
import read
import write

def l(self):
    read.start()                    # getting error

def k(self):
    write.write()


app = wx.App()
first = wx.Dialog(None, -1, title='title', size=(200, 100))
panel = wx.Panel(first, -1)
panel.SetBackgroundColour('black')
bt1 = wx.Button(panel, -1, 'READ', size=(100, 100), pos=(1, 1))
bt1.SetBackgroundColour('green')
bt2 = wx.Button(panel, -1, 'WRITE', size=(100, 100), pos=(1, 2))
bt2.SetBackgroundColour('red')
first.Bind(wx.EVT_BUTTON, l, bt1)     # when bt1 is clicked, l() is executed
first.Bind(wx.EVT_BUTTON, k, bt2)     # when bt2 is clicked, k() is executed

sizer = wx.BoxSizer(wx.HORIZONTAL)

sizer.Add(bt1, 1, wx.ALIGN_CENTRE_VERTICAL)
sizer.Add(bt2, 1, wx.ALIGN_CENTRE_VERTICAL)
panel.SetSizer(sizer)
first.Centre()
first.ShowModal()
app.MainLoop()

read.py

import os
import main

def start():
    l = read()                        # makes instance of class read()

class read(wx.Frame):
    blah

write.py

import wx
import os
import main

class write(wx.Frame):                 # there is no start function, but still works
    bleh

you forgot to import wx in your read.py.
after you have added this import line, remove the start thing and try again with read.read(). The First read is the filename and second read after dot is classname.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM