user-interface - Tkinter 问题。按钮操作前的输出显示
问题描述
我正在使用 Tkinter 进行实验。我写了一个小代码,当我按下一个特定的按钮时应该做一些工作。我制作了五个按钮和五个后续功能。在viewlivescores的第一个按钮中,我遇到了一个问题,因为我什至在界面开始之前就看到了该部分的输出。我如何更正此部分,以便仅在单击按钮后才能运行 viewlivescores 功能。
from tkinter import *
from PIL import ImageTk,Image #PIL -> Pillow
from tkinter import messagebox
import pandas as pd
import requests
from html.parser import HTMLParser
from bs4 import BeautifulSoup
from urllib.request import urlopen
import networkx as nx
from tqdm import tqdm
import warnings
from statistics import median
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from bs4 import BeautifulSoup as soup
from urllib.request import urlopen
site = 'http://static.cricinfo.com/rss/livescores.xml'
def viewlivescores():
messagebox.showinfo("This is The Live Scores Interface")
print("You are in Live scores Interface")
#Open that site
site = 'http://static.cricinfo.com/rss/livescores.xml'
op = urlopen(site)
# read data from site
rd = op.read()
# # close the object
op.close()
# scrapping data from site
sp_page = soup(rd,'xml')
match_list = sp_page.find_all('description')
# print(match_list)
for match in match_list:
print(match.get_text())
def viewteamrecords():
messagebox.showinfo("This is team Records Interface")
print("You are in Live scores Interface")
def viewplayerrecords():
messagebox.showinfo("This is Player Records Interface")
print("You are in Player Records Interface")
def viewpartnershipgraph():
messagebox.showinfo("This is Overall Records Interface")
print("You are in Partnerships Record Interface")
def exitmenu():
print("Thank You for Choosing the Program")
root.destroy()
#Main Section
root = Tk()
root.title("Criclytics")
root.minsize(width=400,height=400)
root.geometry("600x500")
# Take n greater than 0.25 and less than 5
same=True
n=2.8
# Adding a background image
background_image =Image.open("Cricket.jpg")
[imageSizeWidth, imageSizeHeight] = background_image.size
newImageSizeWidth = int(imageSizeWidth*n)
if same:
newImageSizeHeight = int(imageSizeHeight*n)
else:
newImageSizeHeight = int(imageSizeHeight/n)
background_image = background_image.resize((newImageSizeWidth,newImageSizeHeight),Image.ANTIALIAS)
img = ImageTk.PhotoImage(background_image)
Canvas1 = Canvas(root)
Canvas1.create_image(300,340,image = img)
Canvas1.config(bg="white",width = newImageSizeWidth, height = newImageSizeHeight)
Canvas1.pack(expand=True,fill=BOTH)
headingFrame1 = Frame(root,bg="#FFBB00",bd=5)
headingFrame1.place(relx=0.2,rely=0.1,relwidth=0.6,relheight=0.16)
headingLabel = Label(headingFrame1, text="Welcome to \n Cricklytics", bg='black', fg='white', font=('Courier',15))
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)
btn1 = Button(root,text="View Live Scores",bg='black', fg='white',command=viewlivescores)
btn1.place(relx=0.28,rely=0.4, relwidth=0.45,relheight=0.1)
btn2 = Button(root,text="View Team Records",bg='black', fg='white',command=viewteamrecords)
btn2.place(relx=0.28,rely=0.5, relwidth=0.45,relheight=0.1)
btn3 = Button(root,text="View Player Records",bg='black', fg='white',command=viewplayerrecords)
btn3.place(relx=0.28,rely=0.6, relwidth=0.45,relheight=0.1)
btn4 = Button(root,text="View Partnership Record",bg='black', fg='white',command=viewpartnershipgraph)
btn4.place(relx=0.28,rely=0.7, relwidth=0.45,relheight=0.1)
btn5 = Button(root,text="Exit The Menu",bg='black', fg='white',command=exitmenu)
btn5.place(relx=0.28,rely=0.8, relwidth=0.45,relheight=0.1)
root.mainloop()
解决方案
推荐阅读
- jquery - JSON Stringify 拆分每个结果
- mongodb - 如何直接更新mongodb并将数据发送到前端
- java - 变量可能尚未在二维数组中初始化
- dialogflow-es - 自定义 Google 琐事或个性测验
- javascript - 如何创建动态 HTML 标头
- angular - cors:从角度发送请求到springboot
- node.js - TypeDI @Inject() 不起作用,但 Container.get() 可以
- json - 解析 JSON 文件时获取行号
- reactjs - 在客户端进行排序和过滤。应该如何处理?
- ruby-on-rails - 发送带有所有子对象或子对象的外键对象