Tkinter窗口显示不正确(条目未显示)

时间:2017-10-11 17:24:07

标签: python python-3.x tkinter

from functools import partial
from random import randint
from tkinter import *

def click3(a,b, c):
    if int(a) == b:
        c.delete(0.0, END)
        c.insert(END,"That's correct!")
    elif int(a) < b:
        c.delete(0.0, END)
        c.insert(END,"A bit higher")
    elif int(a) > b:
        c.delete(0.0, END)
        c.insert(END,"A bit lower")

gtnCorrect = randint(1,1000)
gtnWin = Tk()
gtnWin.title("Guess the number")
gtnWin.configure(bg='black')
Label(gtnWin, text = "Guess a number from 1-1000", bg='black',fg='white',font = '10').grid(row=0,column=0,sticky=W)
gtnGuess = Entry(gtnWin, width = 10, bg='white')
gtnGuess.grid(row = 1,column=0,sticky=W)
op = Text(gtnGuess, width = 20, height = 1, wrap=WORD,background='white')
op.grid(row = 2, column = 0,sticky=W)
part2 = partial(click3, gtnGuess.get(),gtnCorrect,op)
Button(gtnWin, text = "Submit", width = 6, command = part2).grid(row = 3,column=0,sticky=W)

大家好。

我的代码的这部分工作不正常,我想知道是否有人知道原因。当我运行它时,输入框不会显示,只显示标签,文本框和提交按钮。

由于

1 个答案:

答案 0 :(得分:0)

您将op放在gtnGuess内。显示条目 ,只是它填充了文本小部件。

您需要将op的父/主人更改为gtnGuess以外的内容。也许您打算使用gtnWin