2

なぜtkinterがそのStringVar()機能を使わせないのだろうと思っていました。

私のコードの関連部分:

import tkinter as tk, os

font = ("Curlz MT", 14, "bold")
font2 = ("Curlz MT", 10, "bold")

GameName = tk.StringVar()

root = tk.Tk()
root.geometry('240x50+0+0')
root.title("Name?")

EyourName = tk.Entry(font=font, width=16, textvariable=GameName)
EyourName.insert(tk.END, "Waiting...")
EyourName.place(x=8,y=8)

Bok = tk.Button(font=font2, width=2, text="Ok", command=Ok)
Bok.place(x=200, y=8)

root.mainloop()

(完全なプログラムはこちら:http ://www.2shared.com/file/nANE4rSD/Blah_Blah_Blah.html )

エラー:

Traceback (most recent call last):

File "C:\Documents and Settings\SOMENAME\Desktop\David\Python\MonstaWorld\NewGame2.py", 

line 34, in <module>

GameName = tk.StringVar()

File "C:\Python32\lib\tkinter\__init__.py", line 243, in __init__

Variable.__init__(self, master, value, name)

File "C:\Python32\lib\tkinter\__init__.py", line 174, in __init__

self._tk = master.tk

AttributeError: 'NoneType' object has no attribute 'tk'
4

1 に答える 1

3

StringVarsのようなtkinterオブジェクトを使用する前に、tkinterを初期化する必要があります。

root = tk.Tk()現在の場所から以前 の場所に行を移動するGameName = tk.StringVar()と、問題が解決されます。

于 2013-01-10T10:31:29.883 に答える