我在框架内有一个画布,我说过画布应该是 250x250。但出于某种原因,它被创建得更大,在右侧和底部有额外的空间。这是我的代码......有什么想法吗?
from tkinter import *
from tkinter import ttk
from player import player0
alpha = ('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z')
class GUI(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.boardsize = 250
self.sqsize = self.boardsize//5
master.title("Canvas with extra space")
self.initialdraw()
self.grid(row=0,column=0)
def initialdraw(self):
mainframe = ttk.Frame(self, padding=(5,5,5,5))
mainframe.grid(column=0, row=0, sticky=(N, S, E, W))
self.board = Canvas(mainframe, width=self.boardsize, height=self.boardsize,bg='white')
self.board.grid(row=1,column=0)
for row in range(5):
for col in range(5):
top = row * self.sqsize
left = col * self.sqsize
bottom = row * self.sqsize + self.sqsize -2 …Run Code Online (Sandbox Code Playgroud) 所以我的 python 脚本依赖于我创建的另一个模块。该模块读取文本文件。当我从源代码运行并且一切正常时,脚本、模块和它读取的文件通常位于同一目录中。
我用cx_freeze编译,当我运行它时,导入的模块失败。该模块尝试读取该文件并表示找不到它,然后一切就停止了。
该文本文件包含在library.zip 和构建文件夹中(可能没有必要,但我认为这不会有什么坏处)。我决定在读取文件之前打印模块中的工作目录以查看发生了什么,看起来工作目录不是构建文件夹,而是我的用户主目录。
当然,该文本文件不在我的用户的主目录中。我怎样才能解决这个问题?
具体来说,这是一个例子。所有文件都位于同一目录中。
脚本.py:
import hello
Run Code Online (Sandbox Code Playgroud)
你好.py
import os
print(os.getcwd())
f = open('hello.txt','r')
print(f.read())
f.close()
Run Code Online (Sandbox Code Playgroud)
你好.txt
hello!
Run Code Online (Sandbox Code Playgroud)
安装程序.py
import sys
import os
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
includes = ['hello.txt']
zip_inc = ['hello.txt']
build_exe_options = {"packages": ["os"], "include_files": includes, "zip_includes": zip_inc}
setup( name = "test",
version = "0.1",
description = "test",
options = {"build_exe": build_exe_options},
executables = [Executable("script.py")])
Run Code Online (Sandbox Code Playgroud)
我用命令构建:
python setup.py build
Run Code Online (Sandbox Code Playgroud)
然后我在构建目录中运行名为 script …