TKinter how to configure all labels and buttons at once - button

Now, I'm writing a code to change all the buttons and labels color when a button is pressed.
But I get a different error every time.
windows = []
global windows
buttons = []
global buttons
labels = []
global labels
A bunch of code... Then...
def flavor(c):
if c != 0:
c = 0
for w in windows:
w.config(bg = 'black')
for l in labels:
l.config(bg = 'black', fg = 'white')
for b in buttons:
b.config(bg = 'black', fg = 'white')
elif c != 1:
c = 1
for w in windows:
w.config(bg = 'dark green')
for l in labels:
l.config(bg = 'dark green', fg = 'light green')
for b in buttons:
b.config(bg = 'dark green', fg = 'light green')
The error I got nearly all the time and most of time was :
Traceback (most recent call last):
File "C:\Users\Ahmet\Desktop\An interesting experiment\FOBBY.py", line 153, in <module>
main()
File "C:\Users\Ahmet\Desktop\An interesting experiment\FOBBY.py", line 118, in main
thememenu.add_command(label="Plain",command = flavor(0))
File "C:\Users\Ahmet\Desktop\An interesting experiment\FOBBY.py", line 79, in flavor
l.config(bg = 'dark green', fg = 'light green')
AttributeError: 'NoneType' object has no attribute 'config'
Thanks for help

I am willing to bet you are creating your widgets like this:
l = Label(,,,).pack(...)
labels.append(l)
When you do something like foo().bar(), the result is whatever the last function returns. In your case pack (or maybe grid) is the last function to be called and it always returns None. Thus, your lists contain nothing but Nones.

Related

Is there a way to highlight multiple clades of an unrooted phylogenetic tree using one geom_highlight() layer and "type='encircle'"?

This is my first post so please tell me if I am breaking your rules! My problem is described in the comments of this simplified version of my code.
I want to plot an unrooted phylogenetic tree that neatly highlights selected clades.
I like the results of using geom_hilight() from ggtree with type = 'encircle', but I do not like having to individually edit the node and color values for every input. (see method 1)
method 2 is close to what I want, but with the wrong highlight type (roundrect)
method 3 uses the correct highlight type (encircle) but returns an error.
# I don't think all of these packages are needed to reproduce this problem
library(ape)
library(dplyr)
library(GGally)
library(ggalt)
library(ggforce)
library(ggplot2)
library(ggtree)
library(tidyr)
library(tidytree)
library(treeio)
#my pipeline uses the output of RAxML. I made this simpler tree for discussion purposes.
sink("test.tree")
cat("((((((t24:0.8024311261,t11:0.7828436729):0.3048173019,(t21:0.4867131179,t18:0.2167164627):0.7519672168):0.5776117099,t5:0.4223263576):0.5963104749,(t17:0.1558260066,t20:0.41109852):0.09447153704):0.2661841849,((((t6:0.009324073093,t12:0.2732205035):0.7790091021,t10:0.08588226303):0.3282297731,t9:0.2075715209):0.664191803,(((t15:0.5832811284,t14:0.8461383074):0.6081165755,t19:0.5950602938):0.7095833826,t8:0.7146228608):0.7801561591):0.6674923887):0.654328516,(((t13:0.6356930537,t3:0.8536336934):0.8644152461,t2:0.1784738901):0.7129137593,t23:0.8907998055):0.3618239218,((t16:0.1825823467,t7:0.8856151809):0.4720220205,(t22:0.672613536,(t1:0.9215354125,(t4:0.9248593273,t25:0.5937075356):0.3007316259):0.6941311779):0.6789765966):0.2112918347);")
sink()
#import tree
tree1 <- read.tree("test.tree")
#choose root nodes and colors for highlighting clades
group.roots <- c(34, 28, 44, 41)
group.colors <- c("#fd00fe", "#62ce75", "#9a1073", "#4ad9e1")
#write a data frame
g <- data.frame(gnode = group.roots, gfill = group.colors)
#
tree1unrooted <- ggtree(tree1,layout = 'unrooted')
#method 1: I want my plot to look like this, but I do not want to use so many instances of "geom_hilight()"
tree1unrooted + geom_label(aes(label = node)) +
geom_hilight(
node = 34,
alpha = 1,
fill = "#fd00fe",
type = "encircle",
to.bottom = TRUE
) +
geom_hilight(
node = 28,
alpha = 1,
fill = "#62ce75",
type = "encircle",
to.bottom = TRUE
) +
geom_hilight(
node = 44,
alpha = 1,
fill = "#9a1073",
type = "encircle",
to.bottom = TRUE
) +
geom_hilight(
node = 41,
alpha = 1,
fill = "#4ad9e1",
type = "encircle",
to.bottom = TRUE
)
#method 2: I have used this method to highlight multiple clades successfully with "type = 'roundrect'", but the highlighed regions overlap.
tree1unrooted +
geom_hilight(
data = g,
mapping = aes(node = gnode, fill = gfill),
alpha = 1,
type='roundrect',
to.bottom = TRUE
)
#method 3: I need "type = 'encircle'" for my plot. This gives the error: "Error in FUN(X[[i]], ...) : object 'x' not found"
tree1unrooted +
geom_hilight(
data = g,
mapping = aes(node = gnode, fill = gfill),
alpha = 1,
type='encircle',
to.bottom = TRUE
)
This seems like a bug to me, since one wouldn't think changing the fill shape should cause an error when a different shape works with the same syntax.
It appears that the data passed to the geom_hilight layer gets merged with the plot data, and for some reason this step goes with the "encircle" shape.
Anyway, one obvious solution is to program a list of single geom_hilight layers and add that to the plot:
tree1unrooted +
lapply(seq(nrow(g)), function(i) {
geom_hilight(
node = g$gnode[i],
alpha = 1,
fill = g$gfill[i],
type = "encircle",
to.bottom = TRUE
)
})

Options in buildEdge shinyCyJS

I'm making a graph in Shiny using shinyCyJS, I'm building the edges with buildElems that calls buildEdge:
edges = data.frame(
source = c("v1","v2","v3","v4","v4"),
target = c("v2","v3","v4","v2","v1"),targetArrowShape ='triangle',targetArrowColor = "#000000"
)
edges = buildElems(edges, type = 'Edge')
But the parameters aren't working, I want to:
Build a simple arrow from source to target.
Make the edge black.
Write a legend above the edge.
How can I do those? Thanks.
This works:
edges = data.frame(
source = c("v1","v1","v2","v3","v3"),
target = c("v2","v3","v4","v2","v4"),
label = c("7","3","2","2","8"),
lineColor = "#9b9b9b",
curveStyle='bezier',
targetArrowColor = 'black',
sourceArrowColor = 'black',
targetArrowShape ='triangle',
sourceArrowShape = 'none'
)

display problem of glmtree with terminal_panel node_bivplot or node_barplot

I use different decision trees applying to the same data but most of them can display like the following figure
.
When I use glmtree, there is an error at terminal nodes
Error in [.data.frame(X, , which, drop = FALSE) : undefined columns
selected
columncol<-hcl(c(250,10), 200, 60, 1)
labelcol<-hcl(265, 150, 100, 0.9)
indexcol<-hcl(270, 65, 65, 0.9)
#png(file='c:/glmtree-exmaple.png', width = 1024, height = 512)
plot(glm.model, drop_terminal = TRUE,
inner_panel = node_inner(glm.model, fill = c(labelcol, indexcol)),
terminal_panel=node_bivplot(glm.model, pointcol = "black", boxcol = "black", boxfill = "lightgray", bg = "white", cdplot = FALSE), main="glmtree")
#dev.off()
where glm.model is my result obtained from glmtree function.
If I delete the terminal_panel part, it works. But the information of terminal nodes is important, I was wondering if there is any solution that can display the terminal nodes in glmtree by colourfull boxplot?

Unable to change default radius value using folium CircleMarker

I am unable to change the default circle marker size in folium.
This is what my code looks like:
import folium
import pandas as pd
data = pd.read_csv("Volcanoes_USA.txt")
map = folium.Map(location=[46,-120],zoom_start=5)
fg = folium.FeatureGroup(name="My Map")
def colorcode(x):
if x in range(0,1600):
color = 'green'
elif x in range(1600,2200):
color = 'orange'
elif x in range(2200,2800):
color = 'red'
else:
color = 'darkred'
return color
lat = list(data["LAT"])
long = list(data["LON"])
elev = list(data["ELEV"])
for lt,ln,el in zip(lat,long,elev):
fg.add_child(folium.CircleMarker(location = [lt,ln],
radius = 10,
color = 'black',
fill_color = colorcode(int(el)),
fill_opacity = 0.6,
popup = "Elevation: %s meters" %el))
map.add_child(fg)
map.save("Volcanoes1.html")
And this is how my output looks no matter whatever radius value I use.
Can someone please help?
Regards
Updating the folium version to 0.5.0 fixed it. If you are using anaconda like I was, here's the command to update it:
conda update -c conda-forge folium

How to change the color and width of lines with par function in R

I have a question about the par function in R.
I want to change the color and/or width of a line in a graph with par function. (I am using par function because the gaps.plot command below does not allow "col" option to be included. The gaps.plot command is used after the synth command).
So, I used the following command. But I noticed that the lines of the BOX are changed rather than the lines of the GRAPHS.
synth1<-read.csv(file="C:\\Users\\Research\\R\\synthinR_v4.csv",header=TRUE)
attach(synth1)
library("Synth")
dataprep.out34 <- dataprep(foo = synth1, predictors = c("lncdsales", "md1", "md2","md3", "md4", "md5", "md6", "md7", "md8", "md9", "md10", "md11", "yd1", "yd2", "yd3", "yd4", "yd5", "yd6", "yd7", "yd8"), predictors.op = "mean", time.predictors.prior = -13:1, dependent = "lndigital", unit.variable = "artistalbumcode", time.variable = "release", treatment.identifier = 34, controls.identifier = c(1:33, 35:49), time.optimize.ssr = -13:1, time.plot = -13:25)
synth.out34 <- synth(data.prep.obj = dataprep.out34, method = "BFGS")
par(lwd = 2, col="#cccccc")
gaps.plot(synth.res = synth.out34, dataprep.res = dataprep.out34, Ylab = " Log Digital Sales ", Xlab = "Release", Ylim = c(-7, 7) , Main = NA)
Does anyone know how to fix this problem??
Thank you in advance for your willingness to help. I greatly appreciate it!
The col argument to par sets the default plotting colour (i.e. when col is not explicitly specified in plotting calls), but unfortunately col = "black" is hard-coded into the source of gaps.plot.
You can make a modified copy of the function by either (1) viewing the source (F2 in RStudio, or just executing gaps.plot), editing it and assigning it to a new object, or (2) doing something like the following:
gaps.plot2 <- eval(parse(text=gsub('col = "black"', 'col = "red"',
deparse(Synth:::gaps.plot))))
and then using gaps.plot2 as you would use gaps.plot:
gaps.plot2(synth.res = synth.out34, dataprep.res = dataprep.out34,
Ylab = " Log Digital Sales ", Xlab = "Release", Ylim = c(-7, 7) ,
Main = NA)
Alter the lwd similarly. For example to make lines red and have width of 3, use nested gsub calls like this:
gaps.plot2 <- eval(parse(text=gsub('lwd = 2', 'lwd = 3',
gsub('col = "black"', 'col = "red"',
deparse(Synth:::gaps.plot)))))

Resources