Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pygame and tkinter
#1
I keep getting the error message "AttributeError: type object 'Tk' has no attribute 'tk' when trying to start my program. I have tried to change letters of the variable tk and changed the name of the file in order to make it work. I am working with both pygame and tkinter as I would like to put the pygame window in a tkinter environment instead. I have already tried this one, https://stackoverflow.com/questions/2331...thon-frame, though without any result. I used the code of that question to get my code to work.

import pygame

from tkinter import *
import tkinter as tk
from spelare import Paddle
from boll import Ball
from pygame import mixer
pygame.init()
 
root = tk.Tk
embed = tk.Frame(root, width = 500, height = 500) #creates embed frame for pygame window
embed.grid(columnspan = (600), rowspan = 500) # Adds grid
embed.pack(side = LEFT)
screen = pygame.display.set_mode((660,500))
screen.fill(pygame.Color(255,255,255))
pygame.display.init()
pygame.display.update()
pygame.display.set_caption("Pong Game")
Larz60+ write Feb-14-2022, 09:46 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBcode tags on future posts.

Attached Files

.py   testing.py (Size: 3.41 KB / Downloads: 180)
Reply
#2
That's because tk does not have an attribute named Tk. It does have a class named Tk though, so try creating an instance of Tk, like this:
root = tk.Tk()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  migrate code from tkinter to pygame Frankduc 16 3,237 Jun-01-2022, 12:45 PM
Last Post: Frankduc
  Pygame mixer and tkinter music player Kumarkv 1 2,760 May-14-2020, 06:08 PM
Last Post: Larz60+
  Pygame*import pygame ImportError: No module named pygame CASPERHANISCH 1 9,776 Jun-05-2017, 09:50 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020