-1
私はtkinterを使用しています。私は2つの.pyファイルを持っています.1つは「account」と呼ばれ、もう1つは「account_support」と呼ばれ、私がしようとする "とし、その中で、GUIに関連するすべての機能を持っている "これはaccount_support.pyAttributeError: 'module'オブジェクトに 'key'属性がありません
import sys
import webbrowser
import tkMessageBox
try:
from Tkinter import *
except ImportError:
from tkinter import *
try:
import ttk
py3 = 0
except ImportError:
import tkinter.ttk as ttk
py3 = 1
def addaccount():
import account
cmakey = account.Entry.key.get()
acc = account.Entry.accName.get()
print acc
print cmakey
sys.stdout.flush()
def question():
tkMessageBox.showinfo(title="CMA Key", message="")
sys.stdout.flush()
def init(top, gui, *args, **kwargs):
global w, top_level, root
w = gui
top_level = top
root = top
def destroy_window():
# Function which closes the window.
global top_level
top_level.destroy()
top_level = None
if __name__ == '__main__':
import account
account.vp_start_gui()
ためaccount.py
import sys
try:
from Tkinter import *
except ImportError:
from tkinter import *
try:
import ttk
py3 = 0
except ImportError:
import tkinter.ttk as ttk
py3 = 1
import account_support
def vp_start_gui():
'''Starting point when module is the main routine.'''
global val, w, root
root = Tk()
top = Add_Account (root)
account_support.init(root, top)
root.mainloop()
w = None
def create_Add_Account(root, *args, **kwargs):
'''Starting point when module is imported by another program.'''
global w, w_win, rt
rt = root
w = Toplevel (root)
top = Add_Account (w)
account_support.init(w, top, *args, **kwargs)
return (w, top)
def destroy_Add_Account():
global w
w.destroy()
w = None
class Add_Account:
def __init__(self, top=None):
'''This class configures and populates the toplevel window.
top is the toplevel containing window.'''
_bgcolor = '#d9d9d9' # X11 color: 'gray85'
_fgcolor = '#000000' # X11 color: 'black'
_compcolor = '#d9d9d9' # X11 color: 'gray85'
_ana1color = '#d9d9d9' # X11 color: 'gray85'
_ana2color = '#d9d9d9' # X11 color: 'gray85'
font9 = "-family {DejaVu Sans} -size 0 -weight normal -slant " \
"roman -underline 0 -overstrike 0"
top.geometry("400x200+407+266")
top.title("Add Account")
top.configure(highlightcolor="black")
self.menubar = Menu(top,font=font9,bg=_bgcolor,fg=_fgcolor)
top.configure(menu = self.menubar)
self.accName = Entry(top)
self.accName.place(relx=0.35, rely=0.3, relheight=0.11, relwidth=0.44)
self.accName.configure(background="white")
self.accName.configure(font="TkFixedFont")
self.accName.configure(selectbackground="#c4c4c4")
self.Label1 = Label(top)
self.Label1.place(relx=0.25, rely=0.1, height=38, width=176)
self.Label1.configure(activebackground="#f9f9f9")
self.Label1.configure(text='''Add Account''')
self.Label2 = Label(top)
self.Label2.place(relx=0.03, rely=0.3, height=18, width=126)
self.Label2.configure(activebackground="#f9f9f9")
self.Label2.configure(text='''Account Name:''')
self.key = Entry(top)
self.key.place(relx=0.35, rely=0.5, relheight=0.11, relwidth=0.44)
self.key.configure(background="white")
self.key.configure(font="TkFixedFont")
self.key.configure(selectbackground="#c4c4c4")
self.Label3 = Label(top)
self.Label3.place(relx=0.15, rely=0.5, height=21, width=76)
self.Label3.configure(activebackground="#f9f9f9")
self.Label3.configure(text='''CMA Key:''')
self.add = Button(top)
self.add.place(relx=0.53, rely=0.7, height=26, width=107)
self.add.configure(activebackground="#d9d9d9")
self.add.configure(command=account_support.addaccount)
self.add.configure(text='''Add Account''')
self.helpButton = Button(top)
self.helpButton.place(relx=0.8, rely=0.5, height=16, width=17)
self.helpButton.configure(activebackground="#d9d9d9")
self.helpButton.configure(command=account_support.question)
self.helpButton.configure(text='''?''')
if __name__ == '__main__':
vp_start_gui()
、その後で" account_support.py
をACの価値を得るあなたはのkey
プロパティにアクセスしようとしている
cmakey = account.Entry.key.get()
acc = account.Entry.accName.get()
を実行しているとき
def addaccount():
import account
cmakey = account.Entry.key.get()
acc = account.Entry.accName.get()
print acc
print cmakey
sys.stdout.flush()
とcount.pyのキー入力
iは、エラー
File "/home/silicaandpina/VitaTools/psvimgtools-0.1-linux64/gui/psvimgtools/account_support.py", line 29, in addaccount
cmakey = account.Entry.key.get()
AttributeError: class Entry has no attribute 'key'
Worked!ありがとうございました! – SilicaAndPina