我正在尝试使用tkinter创建一个程序,它不断给我这个错误:
in __init__ self.master = TK()
NameError: name 'TK' is not defined
我不确定为什么说我导入tkinter时没有定义TK,有人可以解释我做错了什么。
这是我的代码:
from tkinter import *
class App:
def __init__(self):
self.master = TK()
frame = Frame(self.master)
frame.pack()
self.master.minsize(1080,720)
self.master.maxsize(1080,720)
self.master.title("Music Player")
myapp = App()
myapp.mainloop()
答案 0 :(得分:0)
不应该是public Bitmap resizeBitmapFitXY(int width, int height, Bitmap bitmap){
Bitmap background = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
float originalWidth = bitmap.getWidth(), originalHeight = bitmap.getHeight();
Canvas canvas = new Canvas(background);
float scale, xTranslation = 0.0f, yTranslation = 0.0f;
if (originalWidth > originalHeight) {
scale = height/originalHeight;
xTranslation = (width - originalWidth * scale)/2.0f;
}
else {
scale = width / originalWidth;
yTranslation = (height - originalHeight * scale)/2.0f;
}
Matrix transformation = new Matrix();
transformation.postTranslate(xTranslation, yTranslation);
transformation.preScale(scale, scale);
Paint paint = new Paint();
paint.setFilterBitmap(true);
canvas.drawBitmap(bitmap, transformation, paint);
return background;
}
;它应该是TK
。
答案 1 :(得分:0)
它是Tk
,而不是TK
。看一下tkinter的documentation中给出的这个小代码。最后三行是给你的。
import tkinter as tk
...
root = tk.Tk()
app = Application(master=root)
app.mainloop()
事实上,我认为你是在试用文档页面中的代码,但是你错过了它!