社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

将python日历插入tkinter标签

jim leahy • 5 年前 • 1275 次点击  

我写的代码有问题。当我插入变量时 calendar2019 进入Tkinter标签 LabelCalen 它不会出现在窗口 root4 ,和窗口 根4 一点都没有。

import calendar
import tkinter as tk

def CalScr():
    calendar2019 = calendar.calendar(2019)#creating calender variable
    root4 = tk.Tk()
    labelCalen= tk.Label(root4, text = calendar2019, )
    root4.mainloop
CalScr()

压延机应该印在标签上 拉贝尔

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/44042
 
1275 次点击  
文章 [ 1 ]  |  最新文章 5 年前
martineau
Reply   •   1 楼
martineau    6 年前

问题之一是您没有调用 mainloop 因为你忽略了 () . 另一个是你没有给标签一个位置。

#! /usr/bin/env python
import calendar
import tkinter as tk
def CalScr():
    calendar2019 = calendar.calendar(2019) #creating calender variable
    root4 = tk.Tk()
    labelCalen= tk.Label(root4, text = calendar2019, font=("Courier New", 14))
    labelCalen.grid(column=0, row=0)
    root4.mainloop()
CalScr()

这也将字体设置为固定间距,否则日历将无法正确对齐。