Python,使用tkinter的程序不显示窗口
我无法显示此代码的窗口。我使用终端运行文件,没有错误,但它不会显示程序。我看不到缺少什么(可能在初始化期间)。非常感谢您的帮助 代码如下:Python,使用tkinter的程序不显示窗口,python,tkinter,tkinter-canvas,Python,Tkinter,Tkinter Canvas,我无法显示此代码的窗口。我使用终端运行文件,没有错误,但它不会显示程序。我看不到缺少什么(可能在初始化期间)。非常感谢您的帮助 代码如下: #9.3 Select geometric figures from tkinter import * #Setting up your interface class geometricFig: #creating window def __int__(self): window = Tk() window.ti
#9.3 Select geometric figures
from tkinter import *
#Setting up your interface
class geometricFig:
#creating window
def __int__(self):
window = Tk()
window.title("Select and Fill")
self.canvas = Canvas(window, width = 200, height = 100, bg = "white")
self.canvas.pack()
#rectangle frame option
frame = Frame(window)
frame.pack()
self.v1 = StringVar()
rect = Radiobutton(frame,
text = "Rectangle",
command = self.shapeFill,
variable = self.v1,
value = '1')
#oval frame option
oval = Radiobutton(frame,
text = "Oval",
command = self.shapeFill,
variable = self.v1,
#new value will allow us to toggle back to rectangle
value = '2')
#frame for fill check
self.v2 = StringVar()
cbtFill = Checkbutton(frame, text = "Fill",
command = self.shapeFill,
variable = self.v2)
#placing widgets within a grid on GUI
rect.grid(row=1, column = 1)
oval.grid(row=1, column = 2)
cbtFill.grid(row=1, column = 3)
#call the mainloop
window.mainloop()
#display rectangle
def DisplayRect(self):
self.canvas.delete("rect", "oval")
self.canvas.create_rectangle(10, 10, 190, 90, tags = "rect")
#display oval
def DisplayOval(self):
self.canvas.delete("rect", "oval")
self.canvas.create_rectangle(10, 10, 190, 90, tags = "oval")
#fill process
def shapeFill(self):
self.canvas.delete("rect", "oval")
#white fill if self.ve is 0 (false), else color is red
color = "white" if self.v2.get() == "0" else "red"
#if self.ve is 1 (true) and rectangle, fill
if self.v1.get() == '1' :
self.canvas.create_rectangle(10, 10, 190, 90,
tags = "rect",
fill = color)
#if self.v1 is 1 (true) and oval, fll
else:
self.canvas.create_oval(10, 10, 190, 90,
tags = "oval",
fill = color)
geometricFig()
您在类初始化方法中有一个输入错误:
def __int__(self):
替换为:
def __init__(self):