所以就像我有这个代码一样,我正在编辑/修改它以使它工作,有什么帮助吗?
继承我的错误
Traceback (most recent call last):
File "C:\Users\Andrew\Desktop\Injector.py", line 42, in <module>
f = Injector()
File "C:\Users\Andrew\Desktop\Injector.py", line 18, in __init__
self.__openInjector()
File "C:\Users\Andrew\Desktop\Injector.py", line 33, in __openInjector
Tkinter.Button(root, text='Inject!', command=self.runInjectorCode).pack()
NameError: name 'Tkinter' is not defined
这是我的代码:
try:
# for Python2
from Tkinter import *
except ImportError:
# for Python3
from tkinter import *
class Injector:
def __openInjector(self):
root = Tk()
root.geometry('600x400')
root.title('Toontown Rewritten Injector')
root.resizable(False, False)
def __init__(self):
self.code = ''
self.__openInjector()
def runInjectorCode(self):
exec(self.code.get(1.0, 'end'), globals())
def __openInjector(self):
root = Tk()
root.geometry('600x400')
root.title('Toontown Rewritten Injector')
root.resizable(False, False)
frame = Frame(root)
self.code = Text(frame, width=70, height=20)
self.code.pack(side='left')
Tkinter.Button(root, text='Inject!', command=self.runInjectorCode).pack()
scroll = Scrollbar(frame)
scroll.pack(fill='y', side='right')
scroll.config(command=self.code.yview)
self.code.config(yscrollcommand=scroll.set)
frame.pack(fill='y')
f = Injector()
f.go()
请帮助我不知道我做错了什么。我对这个python的东西很新,我修改了另一个根本不起作用的代码。但这必须以某种方式
答案 0 :(得分:5)
Tkinter.Button(root, text='Inject!', command=self.runInjectorCode).pack()
应该是
Button(root, text='Inject!', command=self.runInjectorCode).pack()
当您输入第from Tkinter import *
行时,表示您不再需要将其引用为Tkinter.Thing()
,而应立即将其称为Thing()
See this快速阅读有关如何导入python模块的信息,因为它将在未来为您节省大量的调试
答案 1 :(得分:0)
这是你的第二个问题的答案,即f.go()。你想要做的是因为f.go不是你很可能只想运行注入器的函数所以我会用f来替换f.go应该运行你的代码:)