Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

Python 3 error with Tkinter: _tkinter.TclError: unknown option “-padding”

General Tech Learning Aids/Tools
Max. 2000 characters
Replies

usr_profile.png
Charles Kyobe

User

( 6 months ago )

 

I've been learning tkinter with the help of a python book. However, the python book is written for python 2 and I'm using python 3. This has generated several errors, and up to now I've been able to fix them, with the aid of other questions here. It is a basic program that shows a window with buttons to play 3 games or to destroy the window. When either of the first two games(rock paper scissors and hangman) are opened, they are supposed to open a Toplevel() that has various buttons that lets you play the game. I haven't written the graphics code for the third game yet. They don't play, though, because of an error: _tkinter.TclError: unknown option "-padding" which I haven't found any detail about online. I understand that the unknown option means that that attribute/keyword doesn't exist in my version of tkinter and python 3. The error lines look like: rpsFrame = Frame(rpsWindow, padding = '3 3 12 12', width = 300)

In case you need it, the error and code are below. (this code doesn't run without additional code) (if you want this code I will add it, but I want to keep this shortish)

Here is the full error traceback:

Exception in Tkinter callback

Traceback (most recent call last):
  File "C:\Python34\lib\tkinter\__init__.py", line 1533, in __call__
    return self.func(*args)
  File "E:\Python\Python Book\Graphics\Hangman.py", line 149, in gui
    hmFrame = Frame(hmWindow, padding = "3 3 12 12", width = 300)
  File "C:\Python34\lib\tkinter\__init__.py", line 2582, in __init__
    Widget.__init__(self, master, 'frame', cnf, {}, extra)
  File "C:\Python34\lib\tkinter\__init__.py", line 2122, in __init__
    (widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: unknown option "-padding"

Here is the interface code:

from tkinter import *
import RockPaperScissors
import Hangman
import PokerDice

root = Tk()
root.title("Linux User & Developer's Mega Games Collection")

mainframe = Frame(root, height = 200, width = 500)
mainframe.pack_propagate(0)
mainframe.pack(padx = 5, pady = 5)

intro = Label(mainframe, text = """Welcome to Linux User & Developers Mega
Microgames Collection.
Select one of the following games to play:
""")
intro.pack(side = TOP)

rpsButton = Button(mainframe, text = "Rock, Paper, Scissors",
                   command = RockPaperScissors.gui)
rpsButton.pack()

hmButton = Button(mainframe, text = "Hangman", command = Hangman.gui)
hmButton.pack()

pdButton = Button(mainframe, text = "Poker Dice", command = PokerDice
								 								 
							usr_profile.png
							
Vikrant Srivastava

User

( 6 months ago )

There are virtually no differences between tkinter in 2.x vs 3.x, except for the import statements. This is not a 2.x vs 3.x problem.

The padding option is only valid for ttk.Frame, but you're using tkinter.Frame. For the standard tkinter Frame widget you have the padx and pady options.

what's your interest