Tkinter不允许我在画布上放置条目

如何解决Tkinter不允许我在画布上放置条目

当我自己运行此代码时,它什么也不做。但是当与第二组一起运行时,会产生一个非常奇怪的错误。它旨在创建一个窗口,要求输入一个条目,然后放置一个确认按钮,但该条目不会放置并产生错误。如果删除该条目,该错误消失,但是我需要该条目。

我已经搜索了堆栈溢出问题,却找不到任何解决问题的方法。

如果您对我有改善问题的建议,请在评论中注明!

Traceback (most recent call last):
  File "/Users/Me/PycharmProjects/BT Build 2/GUI.py",line 140,in <module>
    getrounds()
  File "/Users/Me/PycharmProjects/BT Build 2/GUI.py",line 138,in getrounds
    roundgetter.create_window(200,130,window=roundsget)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/__init__.py",line 2809,in create_window
    return self._create('window',args,kw)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/__init__.py",line 2771,in _create
    return self.tk.getint(self.tk.call(
_tkinter.TclError: bad window path name ".!entry"
import tkinter as tk
def getrounds():
    root = tk.Tk()
    roundgetter = tk.Canvas(root,width=400,height=300)
    roundgetter.pack()
    roundsprompt = tk.Label(text="How many rounds would you like to play?")
    roundsget = tk.Entry()
    def confirmed():
        intvar = roundsget.get()
    button1 = tk.Button(root,text='Confirm',command=lambda: confirmed())
    roundgetter.create_window(200,160,window=button1)
    roundgetter.create_window(200,window=roundsget)
    roundgetter.create_window(200,100,window=roundsprompt)
    root.mainloop()

这是主要代码

import time
import random
import tkinter as tk
seed = random.randint(-2147483647,2147483647)
random.seed(seed)

class bcolors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'
class things:
    ownedbarrel = 10
    ownedrefining = 10
    ownedgas = 10
    # will be redefined later
    Finalscore = 10000
    rounds = 16
    barrelcost = 40
    refiningcost = 10
    account = 10000
    gasbid = 0
    refiningbid = 0
    barrelbid = 0
    
me = tk.Tk()
infoteller = tk.Canvas(me,width=430,height=50)
infoteller.pack()
creator = tk.Label(me,text="Welcome to the Belvedere Trading Oil trading simulation Alpha 1.5.4")
system = tk.Label(me,text="Copyright © 2020 Grant Hutchinson")
infoteller.create_window(215,15,window=creator)
infoteller.create_window(215,40,window=system)
me.update()
infoteller.destroy()
time.sleep(3)
def main():
    for x in range(0,things.rounds):
        # cost change calculations
        costchange = random.randint(-4,4)
        refiningcostchange = random.randint(-1,1)
        things.refiningcost = things.refiningcost + refiningcostchange
        things.barrelcost = things.barrelcost + costchange
        things.gascost = things.barrelcost + 10 + costchange * 1.1 + random.randint(-2,2)
        # Stablize
        if things.barrelcost < 10:
            things.barrelcost = things.barrelcost + 3
        if things.barrelcost > 70:
            things.barrelcost = things.barrelcost - 3
        if things.barrelcost < 20:
            things.barrelcost = things.barrelcost + 1
        if things.barrelcost > 60:
            things.barrelcost = things.barrelcost - 1
        if things.refiningcost > 12:
            things.refiningcost = things.refiningcost - 1
        if things.refiningcost < 8:
            things.refiningcost = things.refiningcost + 1
        # total cost calculations
        things.barrelask = things.barrelcost * 1.01
        things.barrelbid = things.barrelcost * 0.99
        things.barrelask = round(things.barrelask,2)
        things.barrelbid = round(things.barrelbid,2)
        things.refiningask = things.refiningcost * 1.05
        things.refiningbid = things.refiningcost * 0.95
        things.refiningask = round(things.refiningask,2)
        things.refiningbid = round(things.refiningbid,2)
        things.gasask = things.gascost * 1.01
        things.gasbid = things.gascost * 0.99
        things.gasask = round(things.gasask,2)
        things.gasbid = round(things.gasbid,2)

        
        root = tk.Tk()

        tellcanv = tk.Canvas(root,width=800,height=500)
        tellcanv.pack()

        l1 = tk.Label(root,text="Oil ask")
        a1 = tk.Label(root,text=things.barrelask)
        l2 = tk.Label(root,text="Oil bid")
        a2 = tk.Label(root,text=things.barrelbid)
        l3 = tk.Label(root,text="Refining ask")
        a3 = tk.Label(root,text=things.refiningask)
        l4 = tk.Label(root,text="Refining bid")
        a4 = tk.Label(root,text=things.refiningbid)
        l5 = tk.Label(root,text="Gas ask")
        a5 = tk.Label(root,text=things.gasask)
        l6 = tk.Label(root,text="Gas bid")
        a6 = tk.Label(root,text=things.gasbid)
        tellcanv.create_window(400,20,window=l1)
        tellcanv.create_window(400,window=a1)
        tellcanv.create_window(400,60,window=l2)
        tellcanv.create_window(400,80,window=a2)
        tellcanv.create_window(400,window=l3)
        tellcanv.create_window(400,120,window=a3)
        tellcanv.create_window(400,140,window=l4)
        tellcanv.create_window(400,window=a4)
        tellcanv.create_window(400,180,window=l5)
        tellcanv.create_window(400,200,window=a5)
        tellcanv.create_window(400,220,window=l6)
        tellcanv.create_window(400,240,window=a6)
        tellcanv.pack()
        root.update()
        # Oil system
        self = tk.Tk()
        oilcanvas = tk.Canvas(self,height=300)
        oilcanvas.pack()
        self.oilget = tk.Entry(self)
        def oilbuy():
            intvar = self.oilget.get()
            print(intvar)
        def oilsell():
            intvar = self.oilget.get()
            print(intvar)
        roundsprompt = tk.Label(self,text="How much oil would you like to trade?")
        buyselector = tk.Button(self,text='Buy',command=oilbuy())
        sellselector = tk.Button(self,text='Sell',command=oilsell())
        oilcanvas.create_window(200,window=roundsprompt)
        oilcanvas.create_window(200,150,window=self.oilget)
        oilcanvas.create_window(180,window=buyselector)
        oilcanvas.create_window(220,window=sellselector)
        root.mainloop()

# get rounds
def getrounds():
    root = tk.Tk()
    roundgetter = tk.Canvas(root,height=300)
    roundgetter.pack()
    roundsprompt = tk.Label(text="How many rounds would you like to play?")
    roundsget = tk.Entry()
    def confirmed():
        intvar = roundsget.get()
        things.rounds = int(intvar)
    button1 = tk.Button(root,window=roundsprompt)
    root.mainloop()
getrounds()

main()

它应该会出现一个窗口,询问您要打几轮,但不会。

解决方法

我不知道您在代码中做了什么(我看了一下,但是太复杂了),如果您的问题是创建更多的窗口,请看一下我对此发表的这篇文章:how to make more windows with tkinter

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-