怎么显示不了var.set里面的内容,只显示了button里面的文字
from tkinter import *
root=Tk()
def callback():
var.set=("吹吧")
frame1=Frame(root)
frame2=Frame(root)
var=StringVar()
var.set=("您所下载的影片包含未成年限制内容,\n请满18岁以后再观")
textLabel=Label(frame1,
textvariable=var,
justify=LEFT) #justfy左对齐
textLabel.pack(side=LEFT)
photo=PhotoImage(file="dd.gif")
imgLabel=Label(frame1,image=photo)
imgLabel.pack(side=RIGHT)
theButton=Button(frame2,text="我已经满了18",command=callback)
theButton.pack()
frame1.pack(padx=10,pady=10)
frame2.pack(padx=10,pady=10)
mainloop()
var.set 不需要加等于号
这样试试:
from tkinter import *
root = Tk()
def callback():
var.set("吹吧")
frame1 = Frame(root)
frame2 = Frame(root)
var = StringVar()
var.set = ("您所下载的影片包含未成年限制内容,\n请满18岁以后再观")
textLabel = Label(frame1,
textvariable=var,
justify=LEFT)# justfy左对齐
textLabel.pack(side=LEFT)
photo = PhotoImage(file="dd.gif")
imgLabel = Label(frame1, image=photo)
imgLabel.pack(side=RIGHT)
theButton = Button(frame2, text="我已经满了18", command=callback)
theButton.pack()
frame1.pack(padx=10, pady=10)
frame2.pack(padx=10, pady=10)
mainloop() zltzlt 发表于 2020-4-11 13:15
var.set 不需要加等于号
这样试试:
这样改了之后就报错了
File "C:\Users\Administrator\Desktop\python\tin2.py", line 7, in callback
var.set("吹吧")
TypeError: 'str' object is not callable
猪猪虾 发表于 2020-4-11 13:27
这样改了之后就报错了
这样呢:from tkinter import *
root = Tk()
def callback():
var.set("吹吧")
frame1 = Frame(root)
frame2 = Frame(root)
var = StringVar()
var.set("您所下载的影片包含未成年限制内容,\n请满18岁以后再观") # 不能加 = 号
textLabel = Label(frame1,
textvariable=var,
justify=LEFT)# justfy左对齐
textLabel.pack(side=LEFT)
photo = PhotoImage(file="dd.gif")
imgLabel = Label(frame1, image=photo)
imgLabel.pack(side=RIGHT)
theButton = Button(frame2, text="我已经满了18", command=callback)
theButton.pack()
frame1.pack(padx=10, pady=10)
frame2.pack(padx=10, pady=10)
mainloop() zltzlt 发表于 2020-4-11 13:29
这样呢:
谢谢老师
页:
[1]