0

Here is my code guys:

from tkinter import *

root = Tk()
theLabel = Label(root, 'Hello World')
theLabel.pack()
root.mainloop()

Here is the error:

Traceback (most recent call last): File "C:/Users/argel/PycharmProjects/day2/rockpaper.py", line 4, in theLabel = Label(root, 'Hello World') File "C:\Users\argel\AppData\Local\Programs\Python\Python36-32\lib\tkinter__init__.py", line 2760, in init Widget.init(self, master, 'label', cnf, kw) File "C:\Users\argel\AppData\Local\Programs\Python\Python36-32\lib\tkinter__init__.py", line 2289, in init classes = [(k, v) for k, v in cnf.items() if isinstance(k, type)] AttributeError: 'str' object has no attribute 'items'

Thank you for your help

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685

1 Answers1

1

Just change theLabel = Label(root, 'Hello World') to theLabel = Label(root, text='Hello World') and it will work.

I have a suggestion to improve your code:

Rather than from tkinter import * use import tkinter as tk.

from tkinter import * is actually discouraged so I strongly recommend you do not use this method.

Remember you would also need to change your script slightly if you do. It would look like this:

import tkinter as tk

root = tk.Tk()
theLabel = tk.Label(root, text='Hello World')
theLabel.pack()
root.mainloop()

For more information the differences between imports please see this post.

I hope it solved your problem.

Xantium
  • 11,201
  • 10
  • 62
  • 89