首页 > 解决方案 > 来自 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 版本?

谢谢你的帮助!

编辑:添加了错误消息和回溯

标签: pythonclasstkintersyntax-error

解决方案


1

在源代码顶部附近:

from tkinker import *

你拼错tkintertkinkerk

2

从行中删除分号import time;

3

def在和之间__init__留一个空格def__init__

4

if在和之间__name__留一个空格if__name__


推荐阅读