当我tkinter.Canvas
使用滚动条执行此操作时,我无法获得正确的单击坐标。例如,如果您使用canv.bind('<Button-1>', on_click)
,那么坐标event.x
将event.y
不会考虑滚动canvas
。您能帮忙告诉我使用什么函数来通过Canvas
单击获取坐标,同时考虑到滚动吗?
FotonPC's questions
我编写了一个程序,它应该在一个控制台窗口中运行 2 个 exe 文件,而它本身以非控制台模式运行pyw
。
os.system('hello.exe\ngetchar_pro.exe')
它启动第一个程序,但第二个程序没有启动。
getchar_pro.exe
- C ++ 中的存根接受输入字符串(这样窗口就不会关闭)
getchar_pro 是单独运行的,当你将它设置为第二行时,它会被忽略。没有错误弹出。如何修复
我制作了 2 个类。该类有一个方法,其中传递对对象的引用。链接是因为对象比较大,需要快速完成。
class RayTracePack {
public:
vector<RayTraceInfo> intersects;
RayTracePack() {
intersects.resize(0);
};
void append(RayTraceInfo& info) {
int i;
if (intersects.size() == 0) {
intersects.push_back(info);
}
else {
if (info.distance > intersects.back().distance) {
intersects.push_back(info);
}
else if (info.distance < intersects[0].distance) {
intersects.insert(intersects.begin(), info);
}
else {
for (i = 0; i < intersects.size() - 2; i++) {
if (intersects[i].distance < info.distance && intersects[i + 1].distance > info.distance) {
intersects.insert(intersects.begin() + i, info);
}
}
}
};
}
};
class RayTraceInfo {
public:
double shift;
double distance;
FlatSprite sprite;
RayTraceInfo(double shift_, double distance_, FlatSprite& sprite_){
shift = shift_;
distance = distance_;
sprite = sprite_;
};
};
我是这样传值的
// rays :: RayTracePack
point = vision_sprites[i].getIntersection(center, to_point);
FlatSprite sp = vision_sprites[i];
rays.append(RayTraceInfo(vision_sprites[i].getShift(point), sqrt(point.sub(center).mul(point.sub(center)).sum()), sp));
给出错误信息:
Ошибка C2664 "void RayTracePack::append(RayTraceInfo &)": невозможно преобразовать аргумент 1 из "RayTraceInfo" в "RayTraceInfo &"
Visual Studio 2022 C++ 我是 C++ 的新手,所以也许我不理解其他地方的引用等。但似乎一切正常。没有找到解决问题的方法。提前致谢
我正在用 Python 编写自己的小型 3D 引擎。我使用了一种技术,您可以从相机拍摄大量光线像素并测量到三角形的距离。但是,即使经过 numpy、优化和 numba 并行化等等,即使在 400 + 400 像素的分辨率下,1000 个三角形的正常对象也会渲染 4-7 分钟,这已经很多了。
有一个新算法的想法 - 你看看相机中从拍摄点到三角形点的片段落在哪个像素上,找到三个像素并使用 pygame 在它们之间制作一个三角形。
但是在互联网上,我没有找到关于如何计算至少一个线段和一个矩形在空间中的交点的明确解释。请帮忙,因为我什至没有完成学业自己想出一个垫子。解决方案。
CPU 和 Windows 的理想解决方案
我有 masm 汇编代码:
include console.inc
.data
var1 dq 179
var2 dq 100
var3 dq 0
.code
Start:
mov var3, var2
add var3, var1
outint var3
exit
end Start
我希望它应该输出 279,但它会在构建时引发错误:
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997. All rights reserved.
Assembling: hello.asm
hello.asm(9) : error A2070: invalid instruction operands
hello.asm(10) : error A2070: invalid instruction operands
我不明白问题是什么,我在互联网上找不到解决方案。我还在这个网站上学习:warmland.ru/cs/masm/
请告诉我,我是新来的 assemblere
这是一个文件浏览器:
from tkinter import *
from tkinter import messagebox as msgbox
from tkinter import simpledialog
from tkinter import ttk
import os,shutil,subprocess
from datetime import datetime
import string
from ctypes import windll
from getpass import getuser as WinGetUsername
import threading
def get_drives():
drives = []
bitmask = windll.kernel32.GetLogicalDrives()
for letter in string.ascii_uppercase:
if bitmask & 1:
drives.append(letter+':\\')
bitmask >>= 1
return drives
win=Tk()
win.title('FotonExplorer')
win.iconphoto(True, PhotoImage(file='img\\app_icon.png'))
class FileFrame(Frame):
def __init__(self,window=None,master=None,width=80,height=25):
self.notepad_exist=False
self.window=window
if os.path.isfile('C:\\Program Files\\Notepad++\\notepad++.exe'):
self.notepad_exist=True
self.drives=get_drives()
self.sfl_dict={}
self.user=WinGetUsername()
ttk.Style().theme_use('vista')
self._w=ttk.Frame(master)
#ttk.Label(self._w,text='Имя').grid(row=0,column=1)
#ttk.Label(self._w,text='Дата создания').grid(row=0,column=2)
#ttk.Label(self._w,text='Тип').grid(row=0,column=3)
self.cmd_img=PhotoImage(file='img\\cmd_img.png')
self.dir_img=PhotoImage(file='img\\dir.png')
self.newdir_img=PhotoImage(file='img\\new_dir.png')
self.desktop_img=PhotoImage(file='img\\desktop.png')
self.documents_img=PhotoImage(file='img\\documents.png')
self.images_img=PhotoImage(file='img\\images.png')
self.videos_img=PhotoImage(file='img\\videos.png')
self.drive_img=PhotoImage(file='img\\drives.png')
self.drives_img=PhotoImage(file='img\\drives2.png')
self.user_img=PhotoImage(file='img\\user.png')
self.music_img=PhotoImage(file='img\\music.png')
self.unselect_img=PhotoImage(file='img\\un-select.png')
self.download_img=PhotoImage(file='img\\download.png')
self.simplefilelist=ttk.Treeview(self._w,height=25)
self.simplefilelist.pack(side=LEFT, fill = 'y')
self.full_libs()
self.simplefilelist.bind('<Button-1>',self.click2)
self.img_lib=os.getcwd()+'\\img\\'
self.filelistframe=ttk.Frame(self._w)
self.filelistframe.pack(fill = 'both', expand=1, side=LEFT)
self.filelistframe2 = ttk.Frame(self.filelistframe)
self.filelistframe2.pack(expand=1, fill = BOTH, side= TOP)
self.tk=master.tk
self.listbox=ttk.Treeview(self.filelistframe2,columns=("1n","2n",'3n'), height=27)
self.listbox.heading("#0", text=" Имя",anchor=W)
self.listbox.heading("1n", text="Дата создания",anchor=W)
self.listbox.heading("2n", text="Тип",anchor=W)
self.listbox.heading("3n", text="Размер",anchor=W)
self.listbox.pack(side=LEFT, fill = 'x', expand=1)
scrolly = ttk.Scrollbar(self.filelistframe2)
self.listbox.config(yscrollcommand=scrolly.set)
scrolly.pack(side=RIGHT,fill=Y)
scrolly.config(command=self.listbox.yview)
hbar=ttk.Scrollbar(self.filelistframe,orient=HORIZONTAL)
hbar.pack(side=BOTTOM, fill = 'x')
hbar.config(command=self.listbox.xview)
self.listbox.config(xscrollcommand=hbar.set)
button_frm = ttk.Frame(self._w)
button_frm.pack(side=LEFT, fill = 'y')
ttk.Button(button_frm,text='Cmd',command=self.cmd_start,image=self.cmd_img).grid(row=0)
ttk.Button(button_frm,text='Новая папка',command=self.new_dir,image=self.newdir_img).grid(row=1)
self.width=width
self.height=height
self.files={}
self.images=[]
self.copy_file=os.getcwd()
self.copy_or_cut=0
self.notepad_plus_plus_img=PhotoImage(file='img\\notepad++.png')
self.listbox.bind('<Double-Button-1>',self.click)
self.context_menu = Menu(tearoff=0,bg='#fffff0',font=('arial',9
))
self.context_menu.add_command(label="Открыть", command=self.OPEN)
self.context_menu.add_command(label="Вставить", command=self.PASTE)
self.context_menu.add_command(label="Копировать", command=self.COPY)
self.context_menu.add_command(label="Вырезать", command=self.CUT)
self.context_menu.add_command(label="Переименовать", command=self.RENAME)
self.context_menu.add_command(label="Удалить", command=self.DELETE)
self.context_menu.add_separator()
self.context_menu.add_command(label="Открыть в блокноте", command=lambda: self.startfile('notepad'))
if self.notepad_exist:
self.context_menu.add_command(label="Открыть в Notepad++", command=lambda: self.startfile('"C:\\Program Files\\Notepad++\\notepad++.exe"'),font=('arial',11),image=self.notepad_plus_plus_img)
self.listbox.bind('<Button-3>',self.context)
os.chdir('C:\\Users\\'+self.user+'\\')
self.full_files()
def full_libs(self):
for it in self.sfl_dict.keys():
self.simplefilelist.delete(it)
self.sfl_dict={}
self.drives=get_drives()
self.simplefilelist.heading("#0", text="Библиотеки и диски",anchor=W)
self.user_column=self.simplefilelist.insert("",0,None,text='Пользователь',image=self.user_img)
self.sfl_dict[self.user_column]='C:\\Users\\'+self.user
self.desktop_column=self.simplefilelist.insert("",1,None,text='Рабочий стол',image=self.desktop_img)
self.sfl_dict[self.desktop_column]='C:\\Users\\'+self.user+'\\Desktop\\'
self.download_column=self.simplefilelist.insert("",2,None,text='Загрузки',image=self.download_img)
self.sfl_dict[self.download_column]='C:\\Users\\'+self.user+'\\Downloads\\'
self.docs_column=self.simplefilelist.insert("",3,None,text='Документы',image=self.documents_img)
self.sfl_dict[self.docs_column]='C:\\Users\\'+self.user+'\\Documents\\'
self.images_column=self.simplefilelist.insert("",4,None,text='Изображения',image=self.images_img)
self.sfl_dict[self.images_column]='C:\\Users\\'+self.user+'\\Pictures\\'
self.video_column=self.simplefilelist.insert("",5,None,text='Видео',image=self.videos_img)
self.sfl_dict[self.video_column]='C:\\Users\\'+self.user+'\\Videos\\'
self.music_column=self.simplefilelist.insert("",6,None,text='Музыка',image=self.music_img)
self.sfl_dict[self.music_column]='C:\\Users\\'+self.user+'\\Music\\'
self.drive_column=self.simplefilelist.insert("",7,None,text='Диски',image=self.drive_img)
self.sfl_dict[self.drive_column]='.'
i=0
for logical_drive in self.drives:
i+=1
logdrive=self.simplefilelist.insert(self.drive_column,i,None,text=logical_drive,image=self.drives_img)
self.sfl_dict[logdrive]=logical_drive
self.simplefilelist.insert("",8,None,text=' ')
def strhex(self,st):
a='0123456789ABCDEF'
return a[st//256]+a[st%256//16]+a[st%16]
def check_size(self,fn):
bsize=os.path.getsize(fn)
if bsize>2**30:
return str(bsize//2**30)+'Гб'
if bsize>2**20:
return str(bsize//2**20)+'Мб'
if bsize>2**10:
return str(bsize//2**10)+'Кб'
else:
return str(bsize)+'Б'
def new_dir(self):
newname=simpledialog.askstring('Введите имя новой папки!','Введите имя: ')
os.makedirs(newname)
self.full_files()
def click2(self,event=None):
el=self.sfl_dict[self.simplefilelist.selection()[0]]
if el!='..':
try:
os.chdir(el)
self.full_files()
except:
msgbox.showerror('Ошибка','Не удалось открыть папку или диск!')
def click(self,event=None):
el=self.files[self.listbox.selection()[0]]
#if(1):
try:
if self.isfile(el):
os.startfile(el)
else:
os.chdir(el+'\\')
self.full_files()
except:
msgbox.showerror('Ошибка','Не удалось открыть файл или директорию!')
def full_files(self):
def process():
for it in self.files.keys():
self.listbox.delete(it)
files=['..']+list(os.listdir())
self.images=[]
self.files={}
i=1
for ob in files:
if self.isfile(ob):
if '.' in ob: res='.'+ob.split('.')[-1]
else: res='Файл'
else:
res='Папка'
if self.isfile(ob):
try:
self.images+=[PhotoImage(file=self.img_lib+ob.split('.')[-1]+'.png')]
self.files[self.listbox.insert("",i,None,text=ob, values=(str(datetime.fromtimestamp(int(os.path.getctime(ob)))),res,self.check_size(ob)),image=self.images[-1])]=ob
except:
self.images+=[PhotoImage(file=self.img_lib+'who.png')]
self.files[self.listbox.insert("",i,None,text=ob, values=(str(datetime.fromtimestamp(int(os.path.getctime(ob)))),res,self.check_size(ob)),image=self.images[-1])]=ob
else:
self.files[self.listbox.insert("",i,None,text=ob, values=(str(datetime.fromtimestamp(int(os.path.getctime(ob)))),res,self.check_size(ob)),image=self.dir_img)]=ob
if i%200==199:
self.window.update_idletasks()
self.window.update()
i+=1
self.window.update()
self.window.update_idletasks()
process()
def round_word(self,word,n):
if len(word)>n-1:
return word[:n-4]+'... '
else:
return word+' '*(n-len(word))
def isfile(self,name):
return os.path.isfile(name)
def PASTE(self):
mandms = None
def process():
print(mandms)
if self.copy_or_cut==0:
if self.isfile(self.copy_file):
shutil.copyfile(self.copy_file, os.getcwd()+'\\'+self.copy_file.split('\\')[-1])
else:
shutil.copytree(self.copy_file, os.getcwd()+'\\'+self.copy_file.split('\\')[-1]+'\\')
else:
if self.isfile(self.copy_file):
shutil.copyfile(self.copy_file, os.getcwd()+'\\'+self.copy_file.split('\\')[-1])
os.remove(self.copy_file)
else:
shutil.copytree(self.copy_file, os.getcwd()+'\\'+self.copy_file.split('\\')[-1]+'\\')
shutil.rmtree(self.copy_file)
self.full_files()
mandms = threading.Thread(target=process)
mandms.start()
self.full_files()
def COPY(self):
el=self.files[self.listbox.selection()[0]]
self.copy_file=os.getcwd()+'\\'+el
self.copy_or_cut=0
def CUT(self):
el=self.files[self.listbox.selection()[0]]
self.copy_file=os.getcwd()+'\\'+el
self.copy_or_cut=1
def RENAME(self):
el=self.files[self.listbox.selection()[0]]
newname=simpledialog.askstring('Введите новое имя!','Старое имя: '+el)
os.rename(os.getcwd()+'\\'+el,os.getcwd()+'\\'+newname)
self.full_files()
def startfile(self,prgrm):
el=self.files[self.listbox.selection()[0]]
try:
if self.isfile(el):
os.popen(prgrm+' '+el)
except:
msgbox.showerror('Ошибка','Не удалось открыть папку или директорию!')
def DELETE(self):
el=self.files[self.listbox.selection()[0]]
try:
if self.isfile(el):
os.remove(el)
self.full_files()
else:
shutil.rmtree(el)
self.full_files()
except:
msgbox.showerror('Ошибка','Не удалось удалить папку или директорию!')
def OPEN(self):
el=self.files[self.listbox.selection()[0]]
try:
if self.isfile(el):
def process():
os.startfile(el)
threading.Thread(target = process).start()
else:
os.chdir(el)
self.full_files()
except:
msgbox.showerror('Ошибка','Не удалось открыть папку или директорию!')
def cmd_start(self):
subprocess.Popen('cmd')
def context(self,event=None):
try:
self.context_menu.post(event.x_root, event.y_root)
except: pass
filesys=FileFrame(win,win)
filesys.pack(fill=BOTH,expand=1)
win.mainloop()
关键是,当我放置时ttk.Treeview
.pack(expand=1, fill=BOTH)
,它只会拉伸X
,尽管我BOTH
在父框架中的任何地方都放置了expand
.
为什么不延伸Y
。怎么做?
我附上问题的截图:
我需要在没有eval
.
例如:
ex = '2*3-(23*2-1)'
print(eval(ex)) # Но это очень грязный метод
有必要计算简单的数值表达式:
**
+
-
/
//
%
*
<
>
==
!=
and
or
有没有办法做到这一点?也许与图书馆?
是否有可能以某种方式使其对齐在所有线上。
不可能的代码示例:
import tkinter as tk
root = tk.Tk()
txt = tk.Text(root)
txt.pack()
txt.insert(tk.END, 'Message')
txt.tag_add('msgtag', 1.0, tk.END)
txt.tag_configure('msgtag', justify = 'justify') # Но я смотрел на https://www.tcl.tk/man/tcl8.6/TkCmd/text.htm но там justify можно поставить только как right | left | center
txt.config(justify = 'justify') # или так , но так нельзя тоже
root.mainloop()
有没有办法在单词之间插入空格?或者找出字符串中缺少多少空格?