鱼C论坛

 找回密码
 立即注册
楼主: 小甲鱼

[Tkinter] Tkinter 窗口组件:Label

  [复制链接]
发表于 2017-12-12 14:41:34 | 显示全部楼层
因吹斯听
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-12-14 18:03:15 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-12-16 09:59:30 | 显示全部楼层
分享一个错误案例:如果将程序的名字命名为tkinter.py,在pycharm里运行时会报错 AttributeError: module 'tkinter' has no attribute 'Tk'
解决方案:修改文件名。
参考:https://stackoverflow.com/questi ... ter-has-no-attribut
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-12-21 17:49:12 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-12-27 10:09:12 | 显示全部楼层
123
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-12-30 20:54:09 | 显示全部楼层
在哪里下载呢……
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-12-30 20:57:11 | 显示全部楼层
知道了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-1-1 13:40:14 | 显示全部楼层
好东西,蟹蟹小甲鱼老湿
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-1-3 22:20:23 | 显示全部楼层
学习了~
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-1-23 10:46:48 | 显示全部楼层
2.jpg
这里好像有点问题,等于是pack()后再赋值给了w了,似乎应该如下写哈
  1. v = StringVar()
  2. w = Label(master,textvariable = v)
  3. w.pack()
  4. v.set("~新的文本~")
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2018-2-21 20:13:12 | 显示全部楼层
学习了,很详细呀,支持下
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-3-2 16:29:29 | 显示全部楼层
求助:我这个计算器在按数字的过程中,label1、label2的显示数字不会变化???

  1. from tkinter import *

  2. master = Tk()
  3. group2 = LabelFrame(master).grid(padx=0, pady=0)
  4. group1 = LabelFrame(master).grid(padx=0, pady=50)

  5. # 存放正在输入的数字、以及两个用于实际计算的数字:
  6. num = []
  7. operator = ''
  8. operator_result = 0
  9. num_result = 0
  10. counter1 = 0
  11. counter2 = 0

  12. def num_get():
  13.     num2 = num.copy()
  14.     num1 = ''
  15.     global num_result
  16.     if num2[-1] == '.':
  17.         num2.append('0')
  18.     for each in num2:
  19.         num1 += each
  20.     num_result = float(num1)
  21.     print(num_result)
  22.      
  23. def cbp():
  24.     num.append('.')
  25.     num_get()
  26. def cb0():
  27.     num.append('0')
  28.     num_get()
  29. def cb1():
  30.     num.append('1')
  31.     num_get()
  32. def cb2():
  33.     num.append('2')
  34.     num_get()
  35. def cb3():
  36.     num.append('3')
  37.     num_get()
  38. def cb4():
  39.     num.append('4')
  40.     num_get()
  41. def cb5():
  42.     num.append('5')
  43.     num_get()
  44. def cb6():
  45.     num.append('6')
  46.     num_get()
  47. def cb7():
  48.     num.append('7')
  49.     num_get()
  50. def cb8():
  51.     num.append('8')
  52.     num_get()
  53. def cb9():
  54.     num.append('9')
  55.     num_get()

  56. def cba():
  57.     global num, operator, operator_result, num_result, counter1, counter2
  58.     if not counter1:
  59.         counter1 = num_result
  60.     else:
  61.         counter2 = num_result
  62.     num = []
  63.     operator = '+'
  64. def cbm():
  65.     global num, operator, operator_result, num_result, counter1, counter2
  66.     if not counter1:
  67.         counter1 = num_result
  68.     else:
  69.         counter2 = num_result
  70.     num = []
  71.     operator = '-'
  72. def cbl():
  73.     global num, operator, operator_result, num_result, counter1, counter2
  74.     if not counter1:
  75.         counter1 = num_result
  76.     else:
  77.         counter2 = num_result
  78.     num = []
  79.     operator = '*'
  80. def cbd():
  81.     global num, operator, operator_result, num_result, counter1, counter2
  82.     if not counter1:
  83.         counter1 = num_result
  84.     else:
  85.         counter2 = num_result
  86.     num = []
  87.     operator = '/'
  88. def cbe():
  89.     global num, operator, operator_result, num_result, counter1, counter2
  90.     if not counter1:
  91.         operator_result = counter1
  92.     else:
  93.         counter2 = num_result
  94.         if operator == '+':
  95.             operator_result = counter1 + counter2
  96.         if operator == '-':
  97.             operator_result = counter1 - counter2
  98.         if operator == '*':
  99.             operator_result = counter1 * counter2
  100.         if operator == '/':
  101.             operator_result = counter1 / counter2
  102.     print(operator_result)
  103.     counter1 = operator_result
  104. def cbc():
  105.     global num, operator, operator_result, num_result, counter1, counter2
  106.     num = []
  107.     operator = ''
  108.     operator_result = 0
  109.     num_result = 0
  110.     counter1 = 0
  111.     counter2 = 0

  112. # 数字1-9
  113. bp = Button(group1, text = '.', width = 2, command = cbp)
  114. bp.grid(row=7, column=2)
  115. b0 = Button(group1, text = '0', width = 6, command = cb0)
  116. b0.grid(row=7, column=0, columnspan=2)
  117. b1 = Button(group1, text = '1', width = 2, command = cb1)
  118. b1.grid(row=6, column=0)
  119. b2 = Button(group1, text = '2', width = 2, command = cb2)
  120. b2.grid(row=6, column=1)
  121. b3 = Button(group1, text = '3', width = 2, command = cb3)
  122. b3.grid(row=6, column=2)
  123. b4 = Button(group1, text = '4', width = 2, command = cb4)
  124. b4.grid(row=5, column=0)
  125. b5 = Button(group1, text = '5', width = 2, command = cb5)
  126. b5.grid(row=5, column=1)
  127. b6 = Button(group1, text = '6', width = 2, command = cb6)
  128. b6.grid(row=5, column=2)
  129. b7 = Button(group1, text = '7', width = 2, command = cb7)
  130. b7.grid(row=4, column=0)
  131. b8 = Button(group1, text = '8', width = 2, command = cb8)
  132. b8.grid(row=4, column=1)
  133. b9 = Button(group1, text = '9', width = 2, command = cb9)
  134. b9.grid(row=4, column=2)
  135. # 运算符号
  136. ba = Button(group1, text = '+', width = 4, height = 3, command = cba)
  137. ba.grid(row=4, rowspan=2, column=3)
  138. bm = Button(group1, text = '-', width = 4, command = cbm)
  139. bm.grid(row=3, column=3)
  140. bp = Button(group1, text = '*', width = 2, command = cbl)
  141. bp.grid(row=3, column=2)
  142. bd = Button(group1, text = '/', width = 2, command = cbd)
  143. bd.grid(row=3, column=1)
  144. be = Button(group1, text = 'Enter', width = 4, height = 3, command = cbe)
  145. be.grid(row=6, rowspan=2, column=3)
  146. bc = Button(group1, text = 'c', width = 2, command = cbc)
  147. bc.grid(row=3, column=0)

  148. # 运算结果
  149. v1 = StringVar()
  150. label1 = Label(group2, background="white", textvariable=v1).grid(row=1, rowspan=4)
  151. v1.set(str(operator_result))

  152. v2 = StringVar()
  153. label2 = Label(group2, background="white", textvariable=v2).grid(row=0, rowspan=4)
  154. v2.set(str(counter1) + str(operator) + str(counter2))

  155. mainloop()
复制代码


想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-3-19 21:36:40 | 显示全部楼层
有点木了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-3-30 22:21:01 | 显示全部楼层
vip能看付费主题吗???
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-4-3 16:52:32 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-4-4 09:59:25 | 显示全部楼层
看不到内容,谁能送我一点鱼币呢?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-4-22 16:28:26 | 显示全部楼层
有点复杂啊
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-4-26 08:36:40 | 显示全部楼层
哈哈,不付费?我书都买了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-5-6 14:51:17 From FishC Mobile | 显示全部楼层
为什么entry组件没有get   delete   insert  这些方法啦
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-5-10 10:39:34 | 显示全部楼层
小甲鱼,请问一下,最后事件循环的时候使用root.mainloop()还是tkinter.mainloop()呢?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-28 05:58

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表