Tkinter Widget Issue - PullRequest
       1

Tkinter Widget Issue

0 голосов
/ 20 октября 2019

Я пытаюсь создать виджет для моего проекта виртуального помощника. Когда я запускаю свой код, все, что я получаю, это пустой виджет с черным фоном. Цвет фона, который я установил, компоненты, которые я добавил, вообще не видны. Может кто-нибудь, пожалуйста, помогите мне в этом? Я размещаю код ниже.

# Sarada Virtual Assistant Project

    # Tk GUI toolkit shipped with python for developing GUI Applications
    import Tkinter
    from Tkinter import *
    from PIL import ImageTk, Image
    import speech_recognition as sr


    class Widget:
        def __init__(self):
            # To create a main window, Tk() method is used
            root = Tk()
            # Name of the main window that will be displayed
            root.title('(Sarada(Version 1.0)))')
            # To set the background color
            root.config(background='Red')
            # To set the size of the window
            root.geometry('350x600')
            # To make the window fixed
            root.resizable(0, 0)
            # To add an icon to the main window
            root.iconbitmap(r"ProjectAI/vegetaIcon.png")
            # To display an Image in the application
            img = ImageTk.PhotoImage(
                Image.open(r"ProjectAI/jarvis.jpg"))
            # Label is a Tkinter widget class, which is used to display an image or
            # a text
            panel = Label(root, image=img)
            # Pack geometry manager packs widgets in rows or columns.
            panel.pack(side="bottom", fill="both", expand="no")
            # StringVar() is used most commonly to monitor changes to tkinter
            # variables if they occur
            self.compText = StringVar()
            self.userText = StringVar()
            # Set the userText variable
            self.userText.set('Click \'Start Listening\' to give commands')
            # LabelFrame() - Simple container widget. Its purpose is to act as a
            # container for complex window layouts
            userFrame = LabelFrame(
                root, text="USER", font=(
                    'Black ops one', 10, 'bold'))
            userFrame.pack(fill="both", expand="yes")

            # To show the message to the user regarding the behaviour of the python
            # application
            left2 = Message(
                userFrame,
                textvariable=self.userText,
                bg='dodgerBlue',
                fg='white')
            left2.config(font=("Comic Sans MS", 10, 'bold'))
            left2.pack(fill='both', expand='yes')

            compFrame = LabelFrame(
                root, text="Sankalp", font=(
                    'Black ops one', 10, 'bold'))
            compFrame.pack(fill="both", expand="yes")

            left1 = Message(
                compFrame,
                textvariable=self.compText,
                bg='Red',
                fg='white')
            left1.config(font=('Comic Sans MS', 10, 'bold'))
            left1.pack(fill='both', expand='yes')

            btn = Button(
                root,
                text='Start Listening!',
                font=(
                    'Black ops one',
                    10,
                    'bold'),
                bg='deepSkyBlue',
                fg='white',
                command=self.clicked).pack(
                fill='x',
                expand='no')
            btn2 = Button(
                root,
                text='Close!',
                font=(
                    'Black Ops One',
                    10,
                    'bold'),
                bg='deepSkyBlue',
                fg='white',
                command=root.destroy).pack(
                fill='x',
                expand='no')

            #speak('Hello, I am Sarada! What should I do for You?')
            self.compText.set('Hello, I am Sarada! What should I do for You?')

        root.bind("<Return>",self.clicked) # handle the enter key event of your keyboard
           # mainloop() -> an infinite loop used to run the application, wait for an
        # event to occur and process the event till the window is not closed
            root.mainloop()

        def clicked(self):
            print('Working')
            query = myCommand()
            self.userText.set('Listening...')
            self.userText.set(query)


    if __name__  == '__main__' :
        widget = Widget()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...