英文:
Cannot get the Tkinter to properly display
问题
我正在为学校做一个项目,所以我尝试使用一个代码,但当我运行代码时,它应该显示标题为'医院管理系统',但它显示为空。
下面的图片是我正在使用的代码。
代码
而不是显示所需的输出,它显示空白输出。
输出
英文:
Im trying to make a project for School, so I tried using a code, but when am running the code, it is supposed to display the heading as 'HOSPITAL MANAGEMENT SYSTEM', but it is showing an empty
the below image has the code im using.
Code
and rather than showing the output needed, it's showing blank output
Output
答案1
得分: 1
这里有一段代码,根据我理解你想要的做了以下处理:
import tkinter as tk
from tkinter import ttk
class App(tk.Tk):
def __init__(self):
super().__init__()
self.title('医院管理系统')
self.geometry('250x250')
self.label = ttk.Label(self, text='医院管理系统')
self.label.pack()
if __name__ == "__main__":
app = App()
app.mainloop()
希望这是你想要的。
英文:
Hi here is a code that make what I understand you want :
import tkinter as tk
from tkinter import ttk
class App(tk.Tk):
def __init__(self):
super().__init__()
self.title('HOSPITAL MANAGEMENT SYSTEM')
self.geometry('250x250')
self.label = ttk.Label(self, text='HOSPITAL MANAGEMENT SYSTEM')
self.label.pack()
if __name__ == "__main__":
app = App()
app.mainloop()
Hope it is what you want
答案2
得分: 0
在你的主函数中执行以下操作:
- 创建一个根 tkinter 窗口
root=Tk()
- 创建一个类的实例并传递对象
Hospital(root)
- 当你准备好运行你的应用程序时,调用
root.mainloop()
英文:
Do that in your main function-
- create a root tkinter window
root=Tk()
- create an instance of class and pass the object
Hospital(root)
- call mainloop when you are ready for your application to run.
root.mainloop()
答案3
得分: 0
You are missing mainloop()
:
您遗漏了mainloop()
:
Don't use wildcard import *
. Use import tkinter as tk
:
不要使用通配符 import *
。使用 import tkinter as tk
:
Snippet (片段):
import tkinter as tk
class Hospital:
def __init__(self, root):
self.root = root
self.root.title('医院管理系统') # Displayed as 'HOSPITAL MANAGEMENT SYSTEM'
self.root.geometry('400x400')
lbltitle = tk.Label(self.root, bd=20, relief=tk.RIDGE,
text='医院管理系统', # Displayed as 'HOSPITAL MANAGEMENT SYSTEM'
fg='red', bg='white',
font=('times new romain', 50, 'bold'))
lbltitle.pack(side=tk.TOP, fill='x')
if __name__ == "__main__":
app = Hospital(tk.Tk())
tk.mainloop()
Screenshot (截图):
英文:
> but when am running the code, it is supposed to display the heading as
> 'HOSPITAL MANAGEMENT SYSTEM'
You are missing mainloop()
Don't use wildcard import *
. Use import tkinter as tk
Snippet:
import tkinter as tk
class Hospital:
def __init__(self, root):
self.root = root
self.root.title('Hostipal System Management')
self.root.geometry('400x400')
lbltitle = tk.Label(self.root, bd=20, relief=tk.RIDGE,
text='Hostipal System Management',
fg='red', bg='white',
font=('times new romain', 50, 'bold'))
lbltitle.pack(side=tk.TOP, fill='x')
if __name__ == "__main__":
app = Hospital(tk.Tk())
tk.mainloop()
Screenshot:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论