我在一个函数中创建了一个简单的画布,我想在画布上显示一个图像.
def start(root):
startframe = tkinter.Frame(root)
canvas = tkinter.Canvas(startframe,width=1280,height=720)
startframe.pack()
canvas.pack()
one = tkinter.PhotoImage('images\one.gif')
canvas.create_image((0,0),image=one,anchor='nw')
Run Code Online (Sandbox Code Playgroud)
当我运行代码时,我得到一个空白的1280x720窗口,没有图像.
我查看了以下网站:http://effbot.org/pyfaq/why-do-my-tkinter-images-not-appear.htm但我不明白如何将他们的例子应用于我的情况(我不知道什么创建引用或如何创建引用,如果这是我的问题).我也看了一些堆栈溢出问题,但他们也没有帮助.
生成错误的简单 tkinker 程序,我以前从未见过: TypeError: object of type: 'Frame' has no len()
我完全不知道为什么会出现此错误,也不知道这意味着什么。
def gui ():
window = tk.Tk()
window.title('DudzRPG ' + version)
#frames
options = tk.Frame()
options1 = tk.Frame()
options2 = tk.Frame()
#widgets
image = tk.Canvas(bg='blue')
opt1=tk.Button()
opt2=tk.Button()
opt3=tk.Button()
opt4=tk.Button()
#packs
image.pack()
options.pack()
options1.pack()
options2.pack()
opt1.pack(options1)
opt2.pack(options1)
opt3.pack(options2)
opt4.pack(options2)
window.mainloop()
Run Code Online (Sandbox Code Playgroud)
该错误似乎源于:
options1 = tk.Frame()
options2 = tk.Frame()
Run Code Online (Sandbox Code Playgroud)
这对我没有意义,因为上面的行几乎相同:
options = tk.Frame()
Run Code Online (Sandbox Code Playgroud)
这是回溯:
Traceback (most recent call last):
File "<string>", line 250, in run_nodebug
File "C:\Users\I.S.B\Google Drive\Dudzo inc python workspace\project\python thing.py", …
Run Code Online (Sandbox Code Playgroud) 我有以下按钮:
option1=tkinter.Button(opt1,text='this is a test to see how many words we can fit in a button and stuff so heres some more words',width=49,height=3,bg='grey',)
Run Code Online (Sandbox Code Playgroud)
这使得一个按钮有了单词see how many words we can fit in a button and stuff so heres som
.
我希望文本向下移动到下一行而不是从按钮的一侧移开.
另外,我怎样才能使文本不居中呢?
python 3.3.3.
如何在创建新对象时运行代码,而无需执行任何单独的调用?换句话说,我如何定义在创建对象期间发生的事情?
例如:
class Apple {
//code here
}
// ...
Apple banana = new Apple();
// ...
Run Code Online (Sandbox Code Playgroud)
如何在我调用时自动运行代码:
Apple banana = new Apple();
Run Code Online (Sandbox Code Playgroud)
例如,如何Apple
在创建新方法时调用其中一个方法Apple
?来自Python,我正在寻找类似的东西__init__
.
当我运行这个代码,食物就像-5一样,它似乎完全跳过if语句并转到函数的下一部分(我只有下面的一部分)
def change_location():
global food
global units
global SP
if food < 0: #problem seems to be here
print '------------------------------------------------------'
print 'not enougth food'
main()
Run Code Online (Sandbox Code Playgroud)
这个概念是,如果你没有食物,你就不能去一个新的地方.我不介意替代这个.
python ×4
tkinter ×3
constructor ×1
if-statement ×1
java ×1
object ×1
python-3.x ×1
typeerror ×1