tkinter窗口不会弹出

huangapple go评论75阅读模式
英文:

tkinter window will not pop up

问题

我正在使用tkinter做一个项目。最近我在我的计算机上切换到了Linux Mint。程序没有错误,但图形界面没有显示出来。我正在使用PyCharm。

import sys
from tkinter import *

THEME_COLOR = "#375362"

class QuizInterface:
    def __init__(self):
        self.window = Tk()
        self.window.title("Quizzler")
        self.window.config(padx=30, pady=30)

        self.card = Canvas(width=300, height=250)
        self.card.create_text(text="问题在这里", font=("arial", 20, "italic"))
        self.card.grid(row=1, column=0, columnspan=2)

        self.score = Label(text="得分: ", font=("arial", 13, "bold"))
        self.score.grid(row=0, column=1)

        true_image = PhotoImage(file="images/true.png")
        self.true_button = Button(image=true_image, highlightthickness=0)

        false_image = PhotoImage(file="images/false.png")
        self.f_button = Button(image=false_image, highlightthickness=0)

        self.window.mainloop()
英文:

I am doing a project with tkinter. I've recently switched to linux Mint on my computer. The program runs fine with no errors, the gui just won't come up. I'm using pycharm.

import sys
from tkinter import *

THEME_COLOR = "#375362"

class QuizInterface:
    def __int__(self):
        self.window = Tk()
        self.window.title("Quizzler")
        self.window.config(padx=30, pady=30)

        self.card = Canvas(width=300, height=250)
        self.card.create_text(text="Question goes here", font=("arial", 20, "italic"))
        self.card.grid(row=1, column=0, columnspan=2)


        self.score = Label(text="Score: ", font=("arial", 13, "bold"))
        self.score.grid(row=0, column=1)

        true_image = PhotoImage(file="images/true.png")
        self.true_button = Button(image=true_image, highlightthickness=0)

        false_image = PhotoImage(file="images/false.png")
        self.f_button = Button(image=false_image, highlightthickness=0)

        self.window.mainloop()

答案1

得分: 2

当一个类被初始化时调用的一个函数是 `__init__`,但你定义了 `def __int__(self):`,所以:

```python
class QuizInterface:
    def __init__(self):
        ...

<details>
<summary>英文:</summary>

One of the function that gets called when a class is intitialized is `__init__`, but you are defining `def __int__(self):`, so:

class QuizInterface:
def init(self):
...


</details>



huangapple
  • 本文由 发表于 2023年2月8日 15:54:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/75382751.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定