Comments (6)
Does anyone have a solution or idea to handle the above task? Couldnt get it to work:-(
from tksheet.
A couple of questions,
- Would it use the columns the user has selected or are the columns hard coded? e.g. 1 and 2
- If it uses the columns the user has selected would it only use the first two columns or subtract all columns after the first from the first e.g. subtract 2, 3, 4 from 1
from tksheet.
Hello, Im so happy to hear from you;-)
User mouse selects an particular area of "two" adjacent columns as in the image above. The selected values of the second column should be substracted from the selected values of the first column. I only need a solution for the first two selected columns. User select an area of "two" adjacent columns, in this selected area the values of second column should be substracted from the values of the first column.
Explanation of the posted images above:
First image: Selected area before substracting second column values from the first column values
Second image: Results after substracting second column values from the first column values
from tksheet.
If your data is in string format you'll have to first convert strings to floats or something before subtracting
edit: this code doesn't check the columns are next to each other, you'll have to add that check if you need it
from tksheet import *
import tkinter as tk
class demo(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.grid_columnconfigure(0, weight=1)
self.grid_rowconfigure(0, weight=1)
self.frame = tk.Frame(self)
self.frame.grid_columnconfigure(0, weight=1)
self.frame.grid_rowconfigure(0, weight=1)
data = [[r for c in range(6)] for r in range(50)]
self.sheet = Sheet(
self.frame,
expand_sheet_if_paste_too_big=True,
data=data,
height=520,
width=930,
)
self.sheet.enable_bindings("all", "edit_index", "edit header", "ctrl_select")
self.sheet.popup_menu_add_command(
"subtract values",
self.subtract_values,
)
self.frame.grid(row=0, column=0, sticky="nswe")
self.sheet.grid(row=0, column=0, sticky="nswe")
def subtract_values(self, event=None):
# to determine if user has cell area or columns selected
columns = sorted(self.sheet.get_selected_columns())
if len(columns) < 2:
# less than 2 columns selected, perhaps the user has a cell area selected
columns = sorted(self.sheet.get_selected_columns(get_cells_as_columns=True))
rows = self.sheet.get_selected_rows(get_cells_as_rows=True)
else:
# user has 2 or more columns selected, use all rows of sheet for calc
rows = range(len(self.sheet.MT.data))
if len(columns) < 2:
return
col_one = columns[0]
col_two = columns[1]
for row in rows:
try:
# this is where you may need to convert your data
val_one = self.sheet.get_cell_data(row, col_one)
val_two = self.sheet.get_cell_data(row, col_two)
new_val = val_one - val_two
self.sheet.set_cell_data(row,
col_one,
value=new_val,
redraw=False)
except Exception as error:
# print (error)
continue
self.sheet.refresh()
app = demo()
app.mainloop()
from tksheet.
Ive implemented your code into my programme........it works like a dream!!! Im so happy!! You are a genius! Is there a way to support your work with a little donation?
Thanks a lot.....you are awesome;-)
from tksheet.
Hey, I'm glad to hear it's working! thanks for letting me know
if you really want to support my work I have a page at buy me a coffee
https://www.buymeacoffee.com/ragardner
from tksheet.
Related Issues (20)
- Add prompt for wrong keyward args in get_sheet_data/get_cell_data/get_row_data/get_column_data HOT 1
- Issue with set_sheet_data HOT 6
- Manually set displayed row index HOT 3
- Dropdown menu fails to open if some rows are hidden HOT 2
- Update cells data using specific conditions on user input. HOT 27
- SyntaxWarning HOT 3
- Currently selected cell rows in sheet vs in data HOT 2
- on Rpi5, OS debian bookworm, tksheet's sheet defined col-w & row-h of 10x16 cells size has slow/lagging mouse's cursor movement HOT 12
- How to fix the maximum size of characters in tksheet ceels HOT 6
- The tabel font does not change. HOT 1
- How to Check if a Check Box is checked in tksheet 7 HOT 1
- How to accept user input even if "enter" is not pressed HOT 4
- Looking to customize scrollbar and scrollbar frame bg HOT 2
- Don't work keyboard UP arrow when navigating through the table of tksheet HOT 1
- Multiple issues with Toggle Select Mode
- Partial Horizontal Scrolling HOT 2
- Rows sorting? HOT 2
- Cell Selection Persistence HOT 2
- Keypad enter button ignored HOT 2
- Quotes multiplies when i copy text from cell with ctrl+c or popup menu. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tksheet.