gpt4 book ai didi

Python,使用 tkinter 的程序不显示窗口

转载 作者:太空宇宙 更新时间:2023-11-04 00:21:02 28 4
gpt4 key购买 nike

我无法显示此代码的窗口。我使用终端运行文件,没有错误,但它不会显示程序。我看不到缺少什么(可能在初始化期间)。非常感谢您的帮助!

代码如下:

#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):

关于Python,使用 tkinter 的程序不显示窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49097594/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com