python - 来自 youtube 的“如何在 Python 中创建医院管理系统”-语法错误
问题描述
我正在尝试使用如何在 Python 中创建医院管理系统 - 完整教程作为编程练习来学习如何定义类。我一直没有进行任何更改,但出现错误(在视频中脚本运行良好)。我在 Windows 10 中使用 Python 3.7.4(64 位)。
# Import packages
from tkinker import *
from tkinter import ttk
import random
import time;
import datetime
import tkinter.messagebox
# Define interface
class Hospital:
def__init__(self, root):
self.root = root
self.root.title("Hospital Management Systems")
self.root.geometry("1350x750+0+0")
self.root.configure(background='powder blue')
cmbNameTablets = StringVar()
Ref = StringVar()
Dose = StringVar()
NumberTablets = StringVar()
Lot = StringVar()
IssuedDate = StringVar()
ExpDate = StringVar()
DailyDose = StringVar()
PossibleSideEffects = StringVar()
FurtherInformation = StringVar()
StorageAdvice = StringVar()
DrivingUsingMachines = StringVar()
HowtoUseMedication = StringVar()
PatientID = StringVar()
PatientNHSNo = StringVar()
PatientName = StringVar()
DateOfBirth = StringVar()
PatientAddress = StringVar()
Prescription = StringVar()
MainFrame = Frame(self.root)
MainFrame.grid()
TitleFrame = Frame(MainFrame, bd = 20, width = 1350, padx = 20, relief = RIDGE)
TitleFrame.pack(side = TOP)
self.lblTitle = Label(TitleFrame, font = ('arial', 40, 'bold'), text = "Hospital Management Systems", padx = 2)
self.lblTitle.grid()
FrameDetail = Frame(MainFrame, bd = 20, width = 1350, height = 500, padx = 20, relief = RIDGE)
FrameDetail.pack(side = BOTTOM)
if__name__ == '__main__':
root = Tk()
application = Hospital(root)
root.mainloop()
错误消息和回溯:
File "<ipython-input-7-e64c65d6c91e>", line 3
def__init__(self, root):
^
SyntaxError: invalid syntax
我希望它看起来像视频中 10:36 的样子(一个相当简单的图形界面)。
我是 python 新手,以前从未定义过类,所以我迷路了。自视频制作(2018 年 8 月)以来语法是否发生了变化,还是因为讲师使用了不同的操作系统/python 版本?
谢谢你的帮助!
编辑:添加了错误消息和回溯
解决方案
1
在源代码顶部附近:
from tkinker import *
你拼错tkinter
了tkinker
k
2
从行中删除分号import time;
3
def
在和之间__init__
留一个空格def__init__
4
if
在和之间__name__
留一个空格if__name__
推荐阅读
- hibernate - 从通过 MySQL/Hibernate 返回的对象列表中在 Thymeleaf 上显示图像
- extbase - 使用 extbase 验证空日期字段的问题
- opencv - 学习割草与未割草的神经网络
- javascript - 如何从 Chrome 中获取图像
- java - 包含日志的 Java 测试报告
- json - 在 symfony 3.4 中使用 ajax 将数据从树枝发送到控制器
- discord - 如何获取@everyone 角色ID?
- javafx - 如何防止在 JavaFX 中按空格键时关闭 AutoCompleteCombobox 弹出菜单?
- c++ - OpenMP 按需嵌套并行
- axon - 如何查看 Axon 数据库中有哪些字段可用?