SuspectAverage5
SuspectAverage5

Reputation: 43

TTK Buttons appearing as TK buttons Python 3.8

I'm using TTK buttons in my tkinter application and they're appearing as the old TK buttons. I don't know why, but I would like to know how I can fix it, and why it happens. The application is basic, so if someone can help me, I would gladly appreciate help. This is my code, it's just some funny EA joke application:

import tkinter
import tkinter as ttk
from tkinter import messagebox

class func(ttk.Frame):
    global ok
    def ok():
        modlabel.destroy()
        button2 = ttk.Button(ea, text="About", command=appear, cursor="hand2")
        button2.pack()
        okbtn.destroy()
        messagebox.showinfo("Notifications", "Your CPU temperature has exceeded 8125℃ \nProlonged use at this temperature may shorten the CPU's lifespan.")
    
    global appear
    def appear():
        global modlabel
        modlabel = ttk.Label(ea, text="Welcome. EA, Electronic Arts Inc. is an American video game company headquartered in Redwood City, California. \nIt is the second-largest gaming company in the Americas and Europe by revenue and market capitalization after \nActivision Blizzard and ahead of Take-Two Interactive, CD Projekt, and Ubisoft as of May 2020.")
        modlabel.pack()
        button.destroy()
        global okbtn
        okbtn = ttk.Button(ea, text="OK", command=ok)
        okbtn.pack()

class app(ttk.Frame):
    global ea
    ea = ttk.Tk()
    ea.title("EA")
    ea.geometry("620x300")
    global button
    button = ttk.Button(ea, text="About", command=appear, cursor="hand2")
    moneylabel = ttk.Label(ea, text="                                                                                                                                                                   99$      69$      100$")
    moneylabel.pack()
    button.pack()
    ea.mainloop()

Upvotes: 0

Views: 131

Answers (1)

acw1668
acw1668

Reputation: 46678

Your code did not import ttk module. The following line just imports tkinter and use ttk as its alias name:

import tkinter as ttk

To import ttk module, use:

from tkinter import ttk

After that you also need to change ttk.Tk() to tkinter.Tk().


Also note that the way you define the two classes is not correct.

Upvotes: 2

Related Questions